Tuesday, August 21, 2012

Compare two folders' contents in Terminal

You should have the need of comparing two folders in Mac.

Here is a free way to do it:

It just requires a quick trip to Terminal to put it to use. The program is called diff, and it’s quite simple to use.

Launch "Terminal" and run the following command:

diff -rq folder1 folder2

It is better to have FULL PATH of those folders. If you get use to Linux/UNIX, you will understand what I said.

This is a pretty simple command, with two command-line switches (-rq). The r tells diff to look at each directory recursively, including subdirectories. The q switch sets diff brief mode. If we didn’t set brief mode, diff would not only tell you which files are different between the two folders, but also show the actual line-by-line differences for any text files that exist in both locations but are not identical. Given that we’re just interested in comparing the folders’ contents, we don’t need that level of detail, so we’ll use brief mode to suppress it. And that’s all there is to it. Here’s how it looks in action:

$ cd phpcode
$ diff -rq comments_new comments_old
Only in comments_new: config.php
Only in comments_old: config_old.php
Only in comments_old: functions.inc

By the way, you can download a program here

No comments:

Post a Comment