Linux Backup changed files of the last 7 days

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

For this you can use find and tar:

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

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

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