Last active
October 21, 2024 10:20
-
-
Save DavMorr/53e3ad5c26d16f4f6be3220b078b19c9 to your computer and use it in GitHub Desktop.
Include hidden files in tar archive
This file contains hidden or 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/ |
@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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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