If you’ve ever found it necessary to compare two directories (folders) to see which files might be different between the two, know that there are tools that make your job easier instead of having to do it manually.
While there are some very valid third-party GUI tools out there, the macOS operating system has a free folder comparison utility built into every Mac. You just need to launch the “Terminal” command line to make it work.
The program is called difference and it is quite simple to use. You have to start ‘Terminal’ in ‘Applications> Utilities’ then use the command CD to change the directory that contains the folders you want to compare.
Folders can be located anywhere, of course, but it’s easier if they’re in the same folder. Once there, just run the following command:
diff -rq folder1 folder2
This is a simple command with two switches on the command line (-rq).
The r indicated difference which examines each directory recursively, including also any subdirectories that the folder may have.
the q the switch is set difference as an abbreviation. If we don’t set the brief mode, difference This would not only tell you which files are different between the two folders, but it would also show the actual differences line by line for any existing text files.
Since we are only interested in comparing the contents of directories, we don’t need this level of detail, so we will use the brief mode to suppress the more advanced process.
And that’s all you have to do. Here’s what it looks like in action (comments_newy comments_old) with the two compared files):
% 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
This is obviously a simple example, but it works just as well in a large folder with hundreds of files. If you want to do more with differenceYou should know that it is capable of much more than simple file comparisons.
Write diff man in the command line if you want to know all its capabilities.
We have another interesting article in which we explain how to fix macOS command line errors.
Original article published in igamesnews United States.