How to Use The macOS Command Line to Compare Two Folders' Contents in Terminal

Bethany Walsh

May 30, 2022

This is a tutorial on comparing the contents of two directories on a Mac using the diff command, which was written in response to a number of questions posed by our audience. The powerful diff program makes it simple to compare the data of two folders on a Mac and shows the differences between them. People are frequently searching online for how to use the macOS command line to compare two folders' contents in Terminal.

With the help of the Terminal, you will learn how to compare two directories and their contents. With this command-line technique, you may make a precise comparison between two directories and save the results in a single file. This is essentially a method for comparing directories that work across several operating systems and platforms since we will be using the command-line tool known as "diff." Since diff is accessible on all Macs in addition to Linux and also other Unix operating systems, we will be using it. Diff is a simple command that can be used to quickly compare the contents of two directories.

Comparing Two Directories' Contents Using Diff

The difference is the program's name, and getting started with it is a breeze. 'Terminal' in 'Applications>'' Utilities' must be opened before you can use the command CD to switch to the directory containing your target folders for comparison. Of course, folders don't have to be in the same folder, but it makes things a lot simpler. Run the following command once you've arrived:

diff -rq folder1 folder2

Two switches are all that are needed to run this command (-rq).

The r signifies a distinction since it does a recursive search of all directories, including any subdirectories.

The q switch is used as a shorthand for the difference. If we don't set the short mode, the difference This would not only identify the files that vary between the two directories, but it would also display the actual differences for any existing text files, line by line.

We don't need this level of information to compare directories, so we'll utilize the short option to turn off the more involved procedure. Those are the only two steps required.

What Is the Best Way to Compare Two Folders for Differences?

Use the Compare Directories option to compare several directories. In the Select Directors dialogue box, you must enter the paths of the directories you want to compare in the dir1 and dir2 boxes. Use this option if you'd want to compare folders inside of another folder.

What Is the Best Way to Compare the Contents Of 2 different Folders?

  • Please turn off all plugins before installing a language pack.
  • You may pick the folder you want to compare by clicking on the Browse button.
  • A comparison may then be set up to begin the comparative process. At the conclusion, click "Continue."
  • The results table includes descriptions and results for a number of files.

How Do I Compare Two Folders' Contents?

The chosen folders will be arranged to the left or right. Click here to see how similar the two files are (File). This utility will compare the contents of both folders in order to generate new lists and modify existing ones. The same files are concealed from view in the output.

On A Mac, How Can I Compare Two Files?

The 'diff' command line tool might be useful for Terminal users' chores. With the Diff application, you can effortlessly compare two files and get a report on any discrepancies in the results.

Is It Possible to Compare Two Folders of Files?

To make a new comparison, choose "Select Files or Folders" in the far-left corner. At the conclusion of each run, the comparison tabs are opened. With a second click on the "Select Files or Folders" option on the far left, you may get started comparing files right away.


'Difference' may be used to further your goals. This tool can do a lot more than just compare files, as you should be aware. Using the command line, type "diff man" to see all of its features. The 'diff' command has a lot of arguments and can be quite powerful; see the 'man diff' command for instructions on how to use diff and all of its capabilities.

Related Stories

Privacy Policy | Terms of Use

© 2022

Contact us at: [email protected]