brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tar --newer-mtime only archives files changed after a date

Archive
~/tips/tip-tar-newer-mtime-recent-files

tar -cf ../recent.tar --newer-mtime='1 day ago' .

Archives only files whose content changed after a date, unlike -N, which also checks ctime.

Sometimes I want a quick archive of just what I touched lately, not the whole folder. GNU tar can filter by date, but there are two similar options and they do not behave the same.

tar -cf ../recent.tar --newer-mtime='1 day ago' .

The help text says --newer-mtime=DATE compares the date and time when the data changed only. The date 1 day ago worked on GNU tar 1.35. The archive goes to the parent folder, because tar refuses to put the archive in itself (archive cannot contain itself; not dumped).

In a folder with old.txt (modified three days ago with touch -d) and new.txt, it stored this:

$ tar -tf ../recent.tar
./
./new.txt

The sibling option -N (--newer) looks like the same thing, but with the same date it also stored the old file:

$ tar -cf ../recent2.tar -N '1 day ago' .
$ tar -tf ../recent2.tar
./
./new.txt
./old.txt

The likely reason is that touch -d had just changed the inode change time of old.txt, and -N looks at that as well as at the modification time. Changing a file’s timestamp is not the only thing that updates that time, so -N can pick up more than you expect. When you only care about the content, --newer-mtime is the safer one.

Caveat: the ./ directory entry is stored as well. And a file that was deleted is not recorded at all, so this is no replacement for a real incremental backup. For that there is tar -g.

Further reading: GNU tar manual

More Archive tips tar -xzf archive.tgz --one-top-level find logs -name '*.log' -print0 | tar --null -T – -czf logs.tgz tar -df backup.tar tar --sort=name --mtime=2026-01-01T00:00:00Z \ tar --exclude-vcs -czf project.tar.gz project/ All Archive tips (7) All topics

Link