Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have two folders containing a number of broken symlinks.

Is there a way to make diff compare the target of the links instead of trying to follow the links?

share|improve this question
I believe there's no option to have it prevent dereferencing the link. First hit on Google shows me the feature request with a proposed patch on the diffutils mailing list: diff: support for --no-dereference option – gertvdijk Jan 28 at 14:06

1 Answer

With 'content of the links' I assume you mean 'target of the link'. If that's correct, then yes, there is. Sort of. And you have to get creatie with shell redirection :)

diff -u <(find /path/to/dir1 -type l -print0 | xargs -0 ls -ld | sort) <(find /path/to/dir2 -type l -print0 | xargs -0 ls -ld | sort)

What this does is run diff with as input the output of two commands:

find /path/to/dir1 -type l -print0 | xargs -0 ls -ld | sort
find /path/to/dir1 -type 2 -print0 | xargs -0 ls -ld | sort

These find | ls | sort commands display all symlinks it can find in dir1 and dir2, together with their targets. So the net result is that you'll see which symlinks are different.

share|improve this answer

Your Answer

 
discard

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.