How to compare files in different folders in Unix?

2

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...

Webbies

Posted 2013-06-02T06:38:39.620

Reputation:

1Have you tried --recursive ? – mogul – 2013-06-02T06:40:14.220

Answers

2

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

jaypal singh

Posted 2013-06-02T06:38:39.620

Reputation: 2 134

1And the -b like the question? – Jonathan Leffler – 2013-06-02T06:59:05.230

@JonathanLeffler Good catch! Fixed the answer. :) – jaypal singh – 2013-06-02T07:00:56.090