by  Marirs

Comparing 2 (two) folders using Terminal

If you want to compare two different directories, to see which files may differ between the two, or, which files are missing from either one of them; there are many ways or tools that can do this job. However, we will do this using a simple command line version that will do the trick quick and easy.

[[email protected]]# diff -rq folder1 folder2
Only in /Users/user/folder1/: file13.md
Only in /Users/user/folder1/: AAA.pdf
Only in /Users/user/folder2/: new mail.eml
Only in /Users/user/folder1/: P.docx
Only in /Users/user/folder2/: COMPANY.doc
Only in /Users/user/folder1/: icons.png
Only in /Users/user/folder1/: New Document.pdf
                    

Not always or everytime or everyday we will be doing such kind of comparing; but if this is your job, go pick/buy a tool.
For once a while operation, we can just do a dirty trick and get done with it.

What is it?

Launch the Terminal (Mac: From spotlight, type terminal and hit enter)

[[email protected]]# diff -rq /path/to/folder1 /path/to/folder2

This will compare between the 2 folders and give you results of which files differ from each other, or which files are there only in either of the folder.

The Switches:

  • -r -> Does a recursive search. If you do not want it to do recursive search, simply ignore the -r switch.
  • -q -> brief mode. When you tell diff to use the -q switch, diff will not give you a detailed output such as actual line-by-line differences for any text files that exist in both locations and that are not identical. Since we are more interested to know only what is there and not there between the folders, the -q switch is optimum.