diff has an option --recursive (-r) to do a comparison between two directories (the files inside them). Is there a way to make diff ignore all socket files and only socket files?

I am using diff --brief -r --no-dereference /var/ /media/mateusz/Database/tmp/duplicity_unpack/var/ to verify part of my backup and I am flooded by entries like Only in /var/lib/samba/private/msg.sock: 10001. These files are socket files that Duplicity failed to backup - and it is not indicating a failed backup.

I am aware that I may write my own processing of output but it has potential for bugs, requires more time and requires me to maintain list of socket files in the filesystem.

Note that empty folders should not be ignored in the comparison.


I don't think this is possible with diff itself without code modifications. You will need to use find to list the required files, which you can then pass to diff without recursion:

find /var/ -type f -exec diff {} /media/mateusz/Database/tmp/duplicity_unpack{} \;

This finds only normal files, as I see no sense in calling diff with any other type, so no sockets, FIFOs, directories, device files, etc.

  • I will try it, but I worry that it will die on large amount of files... – reducing activity Jul 6 '16 at 11:03
  • You shouldn't have a problem: diff has only two files on each call, and find has no known limitations on the number of files, though I guess there must be some ultimate limit to the depth and length of paths. You can list every file in your root file system with find /, so find /var/ should present no difficulty. – AFH Jul 6 '16 at 11:53
  • This has one serious trouble - it is blind to empty folders. For some reason find considers socket files as directories (-type f -o -type d brings back sockets). – reducing activity Jul 7 '16 at 12:13
  • @MateuszKonieczny - I don't understand your comment at all: find does not match sockets on -type d (at least, not on Ubuntu), the questioner wants to exclude sockets, and diff doesn't handle directories (except implicitly with -r). To find sockets, use -type s. – AFH Jul 7 '16 at 12:41
  • "find does not match sockets on -type d (at least, not on Ubuntu)" as I understand (see for example superuser.com/review/suggested-edits/552975) it leads to listing them – reducing activity Jul 7 '16 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.