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

I have two folders which have different folders inside. Those folders also contains different files. I am looking for the command that would give me the difference between those two parent folders. Not just difference of files that are contained in one folder and not in the other, but also difference in files contents.

I have done this so far: diff -rq fold1 fold2 .. But that doesn't give me the difference between the files.

What command could I run?

share|improve this question
Just a guess: Does adding the "-N" flag to the diff command line solve your problem? – jofel Nov 8 '12 at 9:49
Remove the -q, and also look at the -a option (beside the -N already suggested by @jofel). Also, what about reading the fine manual? – Stéphane Chazelas Nov 8 '12 at 10:18
Stephane, I have like 1000 files to be readed manual... – Hommer Smith Nov 8 '12 at 11:34
It may be worth looking at Meld: meldmerge.org – Bernhard Dec 8 '12 at 10:45

Maybe you can use rsync as a trick to do this.

rsync --dry-run --delete --recursive --verbose dir1/ dir2

or, short version

rsync -nrv --delete dir1/ dir2

DON'T FORGET THE --dry-run OR -n OPTION, or the destination directory (dir2) will be identical to source directory (dir1).

This will ouput the differences of two directories, including both directory names and file names and file contents. (and you can even compare 2 directories in 2 different machines)

sending incremental file list
deleting dir3-1/   # this directory (name) doesn't exist in source directory
deleting file2.txt # this file      (name) doesn't exist in source directory
file1.txt          # this file is different (content) from the source files
dir3/              # this directory (name) doesn't exist in destination directory

sent 95 bytes  received 21 bytes  232.00 bytes/sec
total size is 4  speedup is 0.03 (DRY RUN)
share|improve this answer

For the difference in folders, you can try

ls -R fold1 > list1
ls -R fold2 > list2
diff list1 list2.

To diff files, however, I think you'll need to write a script (maybe parse the ls -R output).

A somewhat hackish solution:

find fold1 -type f|while read x; do [ -e fold2/$x ] && diff fold1/$x fold2/$x >> files_diff.out; done

This may not be the most elegant or efficient way to do it, though. I'm sure someone more conversant with Bash can come up with a better way. If you're literate in Perl, I'd suggest using its File::Find module.

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.