« Back to File systems: Frequently Asked Questions

How to compare two directories and find the differences

How to compare and find the differences between two directories?

Use the diff command with the recursive comparison option to see the diffences between two paths.

diff -qr Directory1 Directory2

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

    Related articles

    Like to learn more? Here is a list of articles within the same category or having similar tags.

    Feedback

    Small picture of Michael Boelen

    This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

    Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

    Mastodon icon