Last active
March 9, 2024 11:43
-
-
Save DavMorr/53e3ad5c26d16f4f6be3220b078b19c9 to your computer and use it in GitHub Desktop.
Include hidden files in tar archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
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!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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)