Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff files present in two different directories

Tags:

shell

unix

diff

I have two directories with the same list of files. I need to compare all the files present in both the directories using the diff command. Is there a simple command line option to do it, or do I have to write a shell script to get the file listing and then iterate through them?

like image 748
Sudar Avatar asked Jan 07 '10 11:01

Sudar


People also ask

How can I find the difference between two folders?

Click on the “Select Files or Folders” tab in the far left, to start a new comparison. Each comparison you run opens in a new tab. To start a new comparison, click on the “Select Files or Folders” tab in the far left, change the targets and click “Compare” again.

How do I diff two directories in UNIX?

Use the dircmp command to compare two directories specified by the Directory1 and Directory2 parameters and write information about their contents to standard output. First, the dircmp command compares the file names in each directory.

How do I diff two directories in Linux?

Using Meld Visual Diff and Merge Tool Click on directory comparison and move to the next interface. Select the directories you want to compare, note that you can add a third directory by checking the option “3-way Comparison”. Once you selected the directories, click on “Compare”.


2 Answers

You can use the diff command for that:

diff -bur folder1/ folder2/ 

This will output a recursive diff that ignore spaces, with a unified context:

  • b flag means ignoring whitespace
  • u flag means a unified context (3 lines before and after)
  • r flag means recursive
like image 84
Laurent Etiemble Avatar answered Sep 18 '22 11:09

Laurent Etiemble


If you are only interested to see the files that differ, you may use:

diff -qr dir_one dir_two | sort 

Option "q" will only show the files that differ but not the content that differ, and "sort" will arrange the output alphabetically.

like image 42
Suresh Avatar answered Sep 21 '22 11:09

Suresh