How to compare files in different folders in Unix?

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

1

1 Answer

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
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like