« Back to File systems: Frequently Asked Questions

How to compare two directories and find the differences

The diff command is great for discovering differences between two files. What you might not expect from it, is its ability to compare two directories!

Compare two directories

To see the differences between two directories, we can use diff with the --brief and --recursive options. By providing two directories, this will search in them and highlight what files are only in one of them. If it is available in both, it will compare to see if the file is the same or also differs.

# diff --brief --recursive test1 test2
Files test1/readme.md and test/readme.md differ
Only in test2: file-permissions.md
Only in test1: symbolic-links.md
Only in test1: biggest-directories.md
Only in test2: linux-file-permissions.md

Without the brief output we would also see the exact differences between files. Comparing two directories using this command is amazing, right?

Other questions related to Linux file systems


Is the described answer not working or incorrect, got another tip or question? Share your thoughts!