Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to diff two directories using (well) diff. However, diff actually follows symlinks and compares differences between the targeted files. I can't seem to find a way to not have diff do this. Instead, what I would like to know is whether the targets are the same (or different for that matter). In other words, if the symlinks point to the same file, (in my opinion) they are the same, else they are different and that is all I want diff to tell me when it comes across symlinks during a recursive call.

I've tried looking online but I either find topics relating to dealing with symlinks alone or ignoring them altogether.

share|improve this question

If you add lines like:


to a file .ignore-diff

then you can execute diff(1) like this:

diff -ur -X .ignore-diff

What I would suggest is to create a file of the ignores

find . -type l -exec stat '{}' '+' | grep 'File:' | sort | sed "s/^  File: \`//" | sed s/\'.*// >.ignore-diff

finds all symlinks in subdirectories, get the relevant line(s), sorts them(i like alphabetical things) and boils it down to a plain simple file path for the files that are actually symlinks. it finishes redirecting into .ignore-diff

of course, there is also the possibility of doing the .ignore and then doing that same search again, but taking off the last sed, and add a few more seds to take out all but the destinations.

find . -type l -exec stat '{}' '+' | grep 'File:' | sort | sed "s/^  File: \`//" | sed "s/.*-> \`//" | sed "s/'//g" | sed s/\`// > symlinks-dest

do that for each dir and then you could diff those two symlinks-dest files to compare the symlink destinations.

share|improve this answer
Thanks PsychoData. Seems to be a reasonable solution (in theory). – Ash Sep 10 '13 at 6:47
Not sure how long find will take to execute on a directory as large as mine though. – Ash Sep 10 '13 at 6:59
There seems to be a problem with running diff using an 'ignore' file. After playing around with what you suggested, it turns out that adding something like <dir>/<file> to .ignore-diff doesn't work. Adding just <file> however does work. This is a problem. What if I have a file called <file> in a different sub directory somewhere which I don't want ignored? – Ash Sep 12 '13 at 6:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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