Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

Consider for example a source code file, where the functions are drastically shuffled around. Is there is a command to check if the reordering of lines is the only change?

(that means no lines are added, removed or changed)

share|improve this question
up vote 8 down vote accepted

The simple answer is: "compare the sorted version of both files".
In bash:

diff <(sort file1) <(sort file2)

Obviously, this does not mean the two files have the same semantic as source files of a programming language (supposing are both syntactically correct).

share|improve this answer

I mention this one only because I want someone to write a GNU version...

Brenda S. Baker, formerly of Bell Labs, wrote a system called dup that did what you want to do and more. You could use dup to compare two C-language systems, and find code that's kind-of-duplicated: a function copied and variables renamed or some such minor changes.

The whole SCOg Fiasco could have been avoided if an ethical person at SCO had compared Linux source to The Precious SCO "intellectual property".

share|improve this answer

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.