-
-
Save DavMorr/53e3ad5c26d16f4f6be3220b078b19c9 to your computer and use it in GitHub Desktop.
When you create a tar archive of a directory tree the hidden files are normally not included. Here’s how to include the hidden files. | |
Say you have a web directory called “/var/www/html/mysite/” that contains the following tree: | |
.htaccess | |
index.php | |
logo.jpg | |
style.css | |
admin_dir/.htaccess | |
admin_dir/includes.php | |
admin_dir/index.php | |
Normally you would use the tar command like this: | |
tar czf mysite.tar.gz /var/www/html/mysite/* | |
This way all files are tarred except the .htaccess files. | |
The solution to include hidden files: replace the asterisk (*) by a dot (.): | |
tar czf mysite.tar.gz /var/www/html/mysite/. | |
This way the .htaccess files are included in the tarfile. | |
* Borrowed from: http://www.digitesters.com/linux-include-hidden-files-in-tar-archive/ |
@seidler2547 the difference is that your command will include the directory "mysite" in the tar archive whereas @DavMorr's command will only include the files inside of "mysite" (without the "mysite" directory)
Thanks for teaching me the exact opposite of what you actually planned on teaching LOL
I wanted to zip all files that are visible (and exclude hidden ones), but used .
, and thus, hidden files were included as well. Thankfully you included the wrong way for your goal, which was the right one for mine 😁
Great explanation. Just what I was looking for to demystify some of behavior of tar. THANK YOU!
@seidler2547 the difference is that your command will include the directory "mysite" in the tar archive whereas @DavMorr's command will only include the files inside of "mysite" (without the "mysite" directory)
this is not true
I ran following commands
tar -czf test_dir.tar.gz /var/test
tar -czf test_glob.tar.gz /var/test/.
and the archives' content was exactly the same
tar always preserves paths provided as arguments
@seidler2547 the difference is that your command will include the directory "mysite" in the tar archive whereas @DavMorr's command will only include the files inside of "mysite" (without the "mysite" directory)
this is not true I ran following commands
tar -czf test_dir.tar.gz /var/test
tar -czf test_glob.tar.gz /var/test/.
and the archives' content was exactly the sametar always preserves paths provided as arguments
tar doesnt always perserve paths as arguments. in fact common practice with tar is to have tar switch directories by the -C
arg , or strip them with the --strip-components
arg. in any of those stuations, using a .
instead of the folder name, will not store the files in the folder name.
What's the difference to
tar czf mysite.tar.gz /var/www/html/mysite
?