Super User is a question and answer site for computer enthusiasts and power users. 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

I am trying to do something along the lines of:

diff `ls -1a ./dir1` `ls -1a ./dir2`

But that doesn't work for obvious reasons. Is there a better way of achieving this (in 1 line), than this?

ls -1a ./dir1 > lsdir1
ls -1a ./dir2 > lsdir2
diff lsdir1 lsdir2


share|improve this question
up vote 26 down vote accepted

You were close. In bash you want process substitution, not command substitution:

diff <(ls -1a ./dir1) <(ls -1a ./dir2)
share|improve this answer
+1 and check : Learn something new everyday! – bguiz Jan 4 '11 at 2:52
diff -rq dir1 dir2

using the -r option, walk entire directory trees, recursively checking differences between subdirectories and files that occur at comparable points in each tree. The trick is to use the -q option to suppress line-by-line comparisons

share|improve this answer
@festo : You wree missing the poitn of this question, I don't actually want to diff the contents of the files, I want to diff the output of the ls commands – bguiz Jan 4 '11 at 2:53
+1, Actually, I got the same output with the one caveat, diff -rq reported a linked file as 'No such file or directory'. So, plus one for correct, and frankly simpler usage. (even if IVA's answer is a better 'learning opportunity' for process substitution (>_<) – xtian Oct 18 '13 at 0:40
This is much slower than diffing the file names: the entirety of every file has to be read and compared. – Zaz Sep 30 '14 at 20:39
@Josh of course, because it does recursively.... – Braiam Oct 6 '14 at 19:37
@Braiam: Even if you recursively diff the file names (using rsync with the --dry-run option, for example), it would still be much faster than diff -r. – Zaz Oct 11 '14 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .