Commands.page Logo

How to Archive Modified Files Since Date in Ubuntu

This guide explains how to generate a compressed backup containing only files changed after a specific date on Ubuntu. By combining the find command with tar, you can efficiently save storage space and streamline your backup process without including unchanged data.

Create a Reference File

To filter files by date, you first need to create a temporary file with a timestamp matching your target date. Use the touch command with the -d flag to set this specific time.

touch -d "2023-10-01" /tmp/reference_date

Replace 2023-10-01 with the date from which you want to capture modifications. This file acts as a benchmark for the subsequent search.

Find and Archive Modified Files

Next, use the find command to locate all files newer than your reference file and pipe them directly into tar to create a compressed archive. Run the following command in your terminal:

find /path/to/source -newer /tmp/reference_date -type f -print0 | tar -czvf backup.tar.gz --null -T -

Replace /path/to/source with the directory you wish to backup. This command performs three key actions: 1. find: Searches for files (-type f) modified after the reference file (-newer). 2. -print0: Outputs filenames separated by null characters to handle spaces or special characters safely. 3. tar: Creates a gzip-compressed archive (-czvf) reading the file list from standard input (--null -T -).

Verify and Clean Up

Once the process completes, verify the archive exists and contains the expected data. You can list the contents without extracting them using:

tar -tzvf backup.tar.gz

After confirming the backup is successful, remove the temporary reference file to keep your system clean:

rm /tmp/reference_date