how do I create tar file keeping directory structure intact and excluding some files based on the last modified date

810 Views Asked by At

This is a directory structure:

enter image description here

I want to tar Directory1 with the conditions -

  1. It should include only those files that are modified in the last three days.
  2. Keep the directory structure intact.

The final tared output should be -

enter image description here

1

There are 1 best solutions below

0
Aditya On
find directory1 -type f -mtime -4d | xargs tar -cf your_archive_name

-mtime -4d: find all files which were modified in less than 4 days

(-mtime 3d will find all files which were modified exactly 72 hours 00 minutes 00 seconds ago – this is probably not what you are asking for)

Please stay out of directory1 and directory2 while running this command.

Add -z option – tar -czf – if in addition to archiving the files, you also want to compress them.