Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Following is the directory structure

 Folder1
   subFolder1
     File1.txt
     File2.txt
   subFolder2
     File3.txt
   subFolder3

 Folder2 
   subFolder1
     File1.txt
     File2.txt
   subFolder2
     File3.txt
     File4.txt
   subFolder3
     File5.txt

I want to compare the contents of each file in Folder1 with the corresponding file in the Folder2.

i.e I want to check the contents of Folder1/subFolder1/File1.txt with the contents of Folder2/subFolder1/File1.txt

I used the unix command

     diff -b  Folder1/subFolder1/File1.txt   Folder2/subFolder1/File1.txt

This works! But I would like to do this recursively for each file within the subFolders.

Kindly provide some pointers to this...

share|improve this question

migrated from stackoverflow.com Jun 2 '13 at 20:13

This question came from our site for professional and enthusiast programmers.

1  
Have you tried --recursive ? –  mogul Jun 2 '13 at 6:40

1 Answer 1

up vote 2 down vote accepted

Without any option, running the diff command on two directories will tell you which files only exist in one and not the other, and which are common files. Files that are common in both directories are diffed to see if and how the file contents differ.

To do sub-dirs you need to pass -r option to do recursive search.

So just run the following command and you should get desired results:

diff -br /path/to/Folder1 /path/to/Folder2
share|improve this answer
1  
And the -b like the question? –  Jonathan Leffler Jun 2 '13 at 6:59
    
@JonathanLeffler Good catch! Fixed the answer. :) –  jaypal singh Jun 2 '13 at 7:00
    
Thanks I'll try this. Get back to you. –  Webbies Jun 2 '13 at 7:15
    
It worked. Thanks Everyone –  Webbies Jun 2 '13 at 7:20

Your Answer

 
discard

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