Skip to content

Instantly share code, notes, and snippets.

@DavMorr
Last active March 9, 2024 11:43
Show Gist options
  • Save DavMorr/53e3ad5c26d16f4f6be3220b078b19c9 to your computer and use it in GitHub Desktop.
Save DavMorr/53e3ad5c26d16f4f6be3220b078b19c9 to your computer and use it in GitHub Desktop.
Include hidden files in tar archive
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/
@SDClass
Copy link

SDClass commented Apr 27, 2023

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