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 -d compares an archive with the files on disk

Archive
~/tips/tip-tar-diff-compare-archive

tar -df backup.tar

Reports which files in the archive differ from, or are missing on, the file system.

A backup you never compare is a hope, not a backup. GNU tar can check an archive against the live files, which is a cheap way to see what changed since you made it.

tar -df backup.tar

-d is the short form of --diff (also --compare). The help text says it finds differences between the archive and the file system. Run it from the same place where the archive was made, because the stored paths are relative to there.

This is what it printed after one file was edited and another deleted:

$ tar -cf ../cfg.tar cfg
$ echo a=9 > cfg/app.conf
$ rm cfg/other.conf
$ tar -df ../cfg.tar
tar: cfg/other.conf: Warning: Cannot stat: No such file or directory
cfg/app.conf: Contents differ

The exit code was 1. That makes it usable in a script, as the status says whether anything differed. If you give it a name, it only checks that one:

tar -df ../cfg.tar cfg/app.conf

It printed the same Contents differ line, and again exited with 1.

The caveat is the direction. A file that exists on disk but is not in the archive is not reported. In the same folder cfg/extra.conf had been added, and the output above does not mention it. So tar -d answers the question "is everything in the archive still the same?" and not "is everything on disk in the archive?". For the second one, compare tar -tf with a find list.

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 -cf ../recent.tar --newer-mtime='1 day ago' . tar --sort=name --mtime=2026-01-01T00:00:00Z \ tar --exclude-vcs -czf project.tar.gz project/ All Archive tips (7) All topics

Link