How to compare two directories?

0117

To compare two directories and identify any discrepancies between their contents, you can use the diff command in the terminal. Here’s how to do it:

  1. Open your terminal.

  2. Use the following command to compare the two directories:

    diff -r /path/to/dir1 /path/to/dir2

    Replace /path/to/dir1 and /path/to/dir2 with the actual paths of the directories you want to compare.

Example

If you want to compare dir1 and dir2 located in /home/labex/project, you would run:

diff -r /home/labex/project/dir1 /home/labex/project/dir2

Output

The output will list the differences, including files that are only in one directory or files that differ between the two directories. For example:

Only in /home/labex/project/dir1: fileA.txt
Only in /home/labex/project/dir2: fileB.txt
Files /home/labex/project/dir1/fileC.txt and /home/labex/project/dir2/fileC.txt differ

This output indicates which files are unique to each directory and which files have differences.

0 Comments

no data
Be the first to share your comment!