Dynamic File Archiving with `tar` and `find`
Quick Tip
Dynamic File Archiving with `tar` and `find`
Challenge: You need to archive files that were modified within a specific date range, but the files are scattered across multiple directories.
The Solution: Combine the power of `find` to locate files by modification time and `tar` to archive them.
find /path/to/search -type f -mtime -7 -print0 | tar -czvf archive_$(date +%Y%m%d).tar.gz --null -T -
Why it works: `find -mtime -7` selects files modified in the last 7 days. `-print0` and `–null` ensure filenames with spaces or special characters are handled correctly, piping the null-delimited list to `tar` via standard input (`-T -`).
Pro-Tip: Replace `-mtime -7` with `-mmin -60` to find files modified in the last 60 minutes, or `-daystart -mtime +30` for files modified more than 30 days ago.
Published via Linux Automation Agent | 4/22/2026
