How to display which file differs from the others

If you change the diff format to unified with -u or --unified, the filenames will appear.

# diff -u --from-file file1 file[2-5]
--- file1   2020-10-30 11:02:22.223269990 +0200
+++ file3   2020-10-30 11:02:35.445984702 +0200
@@ -1 +1 @@
-original
+new
--- file1   2020-10-30 11:02:22.223269990 +0200
+++ file5   2020-10-30 11:02:40.625872942 +0200
@@ -1 +1 @@
-original
+new

You can also use a brief output with -q or --brief.

# diff -q --from-file file1 file[2-5]
Files file1 and file3 differ
Files file1 and file5 differ

Another solution might be to run a checksum program, e.g. md5sum, sha1sum, etc. on all the files and see which one has a different checksum than the first one.

On a GNU system you can even combine it with awk like this:

# md5sum file* | awk '{h[$1] = h[$1] " " $2} END {for(k in h) printf("%s:%s\n", k, h[k])}'
88fa9f694690e11239096536ccf2702b: file1 file2 file4
9cd599a3523898e6a12e13ec787da50a: file3 file5

Or you can combine it with uniq like this:

# hashlen=32  # MD5 outputs 32 hexadecimals
# md5sum file* | sort | uniq --group --check-chars=${hashlen}
88fa9f694690e11239096536ccf2702b  file1
88fa9f694690e11239096536ccf2702b  file2
88fa9f694690e11239096536ccf2702b  file4

9cd599a3523898e6a12e13ec787da50a  file3
9cd599a3523898e6a12e13ec787da50a  file5

On a FreeBSD system you can combine it with awk like this:

# md5 file* | awk -F ' = ' '{h[$2] = h[$2] " " substr($1, index($1, "("))} END {for(k in h) printf("%s:%s\n", k, h[k])}' 
9cd599a3523898e6a12e13ec787da50a: (file3) (file5)
88fa9f694690e11239096536ccf2702b: (file1) (file2) (file4)

diffuse can handle the 5 inputs (sudo apt-get install diffuse). From the man page:

Diffuse is a graphical tool for merging and comparing text files. Diffuse is able
to compare an arbitrary number of files side-by-side and gives users the ability
to manually adjust line matching and directly edit files.

Tags:

Diff