view raw
swag antiswag swag antiswag - 11 months ago 29
Linux Question

Linux command to find the difference between two folders

I have two folders, each with sub folders, and I want to see if there are any sub folders in one file that does not exist the other folder. I have tried this command:

diff -r file1 file2

but it does not provide the results that I want.

For example if file1 contains three folders A, B, and C and file 2 contains 1 folder B, then the output should be folders A and C.

diff -r dir1 dir2 | grep dir1 | awk '{print $4}' > difference1.txt


  1. diff -r dir1 dir2 shows which files are only in dir1 and those only in dir2 and also the changes of the files present in both directories if any.
  2. diff -r dir1 dir2 | grep dir1 shows which files are only in dir1
  3. awk to print only filename.