You are on page 1of 1

How to compare two

folders' contents in
Terminal
Launch Terminal (in Applications -> Utilities), and then use the
cd command to change to the directory containing the folders
youd like to compare. Once there, just run this command:
diff -rq folder1 folder2

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 didnt set brief mode, diff would not only
tell you which files are dierent between the two folders, but
also show the actual line-by-line dierences for any text files
that exist in both locations but are not identical. Given that
were just interested in comparing the folders contents, we
dont need that level of detail, so well use brief mode to
suppress it. And thats all there is to it. Heres 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

Obviously, this is a simplistic example, but it works just as well


on a large folder with hundreds of files. If you want to do more
with diff, of course, its capable of much more than just
simple folder comparisons; type man diff to read about its
full capabilities.

You might also like