I need to create a tarball of a given directory. However, I need to make sure hidden files are included too (such as those beginning with .).

Will the following command automatically take the hidden files into account?

tar -cvzf packed.tar.gz mydir

If not, how can I make sure I include hidden files?


Yes, it will.

Files starting with . are not "hidden" in all contexts. They aren't expanded by *, and ls doesn't list them by default, but tar doesn't care about the leading .. (find doesn't care either.)

(Of course, this is one of those things that's easy to find out by experiment.)

  • Thanks. Yes experiment is sometimes a solution to find an answer, but in this case, I am not a unix expert and I know behaviors - in general - can be modified with configuration. What if two systems are not configured the same way? The belief I might build from one system might not be true for another. – Jérôme Verstrynge Feb 17 '12 at 17:55
  • 1
    @JVerstry: Good point. A suggestion, though; a question like "I tried this, and it worked; is it guaranteed?" would have been even better. – Keith Thompson Feb 17 '12 at 18:20
  • tar --help lists several different options, all beginning with --exclude that allow one to exclude various files based on name, pattern, etc. Agreed, experimentation is a great way to test and verify if something works as expected. Make backups regularly! – bsd Feb 17 '12 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.