Linux Backup files changed in the last 7 days

Sometimes it’s useful to backup the files in an folder (and subfolders) which have been changed in the last 7 days.

For this we can use find and tar:

find . -mtime -7 -print | xargs tar cvf "backup-$(date +%y-%m-%d).tar"

If you want to only backup certain file types you can extend the find the following:

find . -iname "*.jpg" -mtime -7 -print | xargs tar cvf "backup-$(date +%y-%m-%d).tar"

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.