I have the following folder structure

| |-C
|   |-1.log
|   |-2.log

I want to collect all the log files and the php file present in the H subdirectory and make into a tar.

I tried tar -czf temp.tar.gz /A/**/*.log /A/D/F/H/php.log but it doesn't seem to search recursively in the A directory.

I am using Amazon Linux

migrated from serverfault.com Jun 2 '16 at 9:30

This question came from our site for system and network administrators.

  • The "**" looks wrong. Try tar -czf temp.tar.gz /A/*/*/*.log /A/D/F/H/php.log – steve Jun 2 '16 at 10:02
  • Is the / character before the A right? Maybe you should try just A/... – Luchostein Aug 22 '16 at 15:07

Don't rely on wildcard matching / shell globbing but instead use the find command to find and list the files you want and send that list to tar to be archived:

find /A/ -type f -print0 -name \*.log | tar -cvf /path/to/file.tar --null -T -
  • That works, but when untarring with tar -xvf test2.tar, it gives me a tar: A/B/2016-04-15.log: Cannot open: Not a directory error. – user3288346 Jun 3 '16 at 1:09

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.