#1126444 wish: diff -rq --print-newest-first should print the newest of the two differing files first

Package:
diffutils
Source:
diffutils
Description:
File comparison utilities
Submitter:
Peter Müller
Date:
2026-01-26 20:15:05 UTC
Severity:
normal
#1126444#5
Date:
2026-01-26 16:54:51 UTC
From:
To:
$ mkdir a b
$ echo "a" > a/f1
$ echo "b" > b/f1
$ echo "b" > b/f2
$ echo "a" > a/f2
$ touch a/f3
$ touch b/f3
$ diff -rq a b
Files a/f1 and b/f1 differ
Files a/f2 and b/f2 differ

In each line, diff prints the files from directory a before the files from directory b. I wish for an option, say, --print-newest-first, such that the newest (with respect to the modification time) file in each pair of differing files is printed first:

$ diff -rq --print-newest-first a b
Files a/f1 and b/f1 differ; the first file has a newer modification time.
Files b/f2 and a/f2 differ; the first file has a newer modification time.

The advantage of this option would be an easier synchronization of the directories. This would allow the user to copy "a/f1 and b/f1" into the exchange buffer with a mouse, paste it into the command line, delete “and ”, and issue commands, e.g.,

$ cwdiff a/f1 b/f1
$ cp -auv a/f1 b/f1
$ cwdiff b/f2 a/f2
$ cp -auv b/f2 a/f2

for which the order of arguments, and I mean for cp here, is important. (On my systen, cwdiff performs a colored wdiff; other typical commands in its place are colordiff, diffuse, xxdiff, diff <(exiftool …) <(exiftool …), diffpdf, … – it's a user's choice.)

As of now, syncing is more tedious: the user has to check which file is newer with

$ ls -l a/f1 b/f1
$ ls -l a/f2 b/f2

and then exchange the order of the arguments in case he or she decides to simply copy the newer file to the older; the exchange involves much more work with keyboard and mouse.

You may ask what should happen if the modification times are equal. In this case, I suggest that the creation/birth times be compared (if present), and should they be equal (or at least one of them be absent), the access times (if present); of course, the wording of “the first file has a newer modification time” has to be adapted accordingly in such cases.

#1126444#10
Date:
2026-01-26 20:12:20 UTC
From:
To:
Correction:

“the exchange involves much more work with keyboard and mouse”
->
“checking the modification times and, if necessary, changing the order of the arguments involve more manual work. The workload for a single pair of files is not overwhelmingly large, but if you sync repeatedly or for many directories or files inside, these (presumably avoidable) workloads sum up considerably.”