Thursday, April 29, 2010

tar doesn't compress .hidden files in the same directory it is run in?

SkyHi @ Thursday, April 29, 2010
Example Directory Contains:

.htaccess

.news

info.txt

info.log


Code:

tar -cvpzf test.tgz ./*
./info.log
./info.txt

What gives, why isn't .htaccess or .news being added to the tar?



Furthermore if there is a .htaccess file in a subdirectory it is compressed.



Example Directory Contains:

.htaccess

.news

info.txt

info.log

/subdir/.htaccess/


Code:

tar -cvpzf test.tgz ./*<br />./info.log<br />./info.txt<br />./subdir/<br />./subdir/.htaccess

Why is this, how do I work-around?

Solution:
Globbing with * does not include hidden files, whereas every file in a
directory (hidden ones included) are put into the archive. So you can
simply do


Code:

$ tar -cvpzf test.tgz .

However, you can force the shell to include hidden files in
globbing, using


Code:

$ shopt -s dotglob<br />$ tar -cvpzf test.tgz ./*<br />$ shopt -u dotglob         # to disable the shell option


REFERENCES
http://www.linuxquestions.org/questions/linux-newbie-8/tar-doesnt-compress-hidden-files-in-the-same-directory-it-is-run-in-730222/