• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 878
  • Last Modified:

tar with --newer-mtime includes all the directories

hello, each night i am running the command

/bin/tar cfz $TARFILENAME --newer-mtime=\"$yesterday 00:00:01-06:00\" /home

Open in new window

It is finding and adding all the files modified OK, but also adding every directory. For my system that is over a GIG and yet total modified files are only a couple 100MB

I looked at the doc and there wasn't anything that jumped out.  tar --incremental will not work in my situation

thanks for any suggestions/help
1 Solution
Duncan RoeSoftware DeveloperCommented:
I think it's inherent in the way tar works. It dumps each directory as it comes to it and then applies the selection criterion to each non-directory file system object therein.
However you can accomplish what you want with a combination of findtar. find's newerXY test can implement the date spec you use
find /home -newermt "yesterday 00:00:01-06:00" -not -type d | tar -T- -czf $TARFILENAME

Open in new window

Be sure to specify -not -type d or it may find /work for example
I think it is looking for modification time of the dir which could be true if any file is added / removed.

find option given above is good for finding all files modified and then adding to tar.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now