Viewing the differences between two directories on Linux servers

This past week I needed to compare the contents of two directories to see if there were any differences. There are a TON of ways to do this, though my preferred way is to use diff with the “-r” (when comparing directories do so recursively) option to compare two folders:

$ find foo1
foo1
foo1/services2
foo1/services

$ find foo2
foo2
foo2/services

$ diff -r foo1 foo2
Only in foo1: services2

Simple, easy and it gives you the output you’re most likely after. Anyone found a simpler solution that this? :)

4 Comments

Jbb  on May 21st, 2011

Rsync -vn dir1 dir2

Add another v for an ls like output.

Has the advantages of being one command and works across servers using host1:dir1 host2:dir2

matty  on May 21st, 2011

Awesome suggestion jbb!

robbyt  on June 21st, 2011

if you just want to check for file names:

find /foo |sort > foo_files.txt
find /bar |sort > bar_files.txt

diff foo_files.txt bar_files.txt

Removing characters from a file name in linux | elizaibeth  on March 21st, 2012

[...] Name The Files You ShareLinux – How to delete specific files in directory that are n days oldViewing the differences between two directories on Linux servers ul.scfw_16px li,ul.scfw_24px li,ul.scfw_32px li,ul.scfw_16px li a,ul.scfw_24px li a,ul.scfw_32px [...]

Leave a Comment