Linux Directories – How to Compare Different Files of Two Directories

diff()directorylinuxpatch-management

There are two directories I'd like to compare. I tried diff but it includes the changes inside the files. All I want is something like this

file a is just in /A 
file b is missing in /A 
file c changed
directory d is missing in /A 
directory e is just in /A

I think this is common when doing full file patching but I don't know a good solution.

Best Answer

You're looking for

diff -rq (dir1) (dir2)

Proof of concept:

#!/bin/sh
#create our test
mkdir -p /tmp/a/b
echo "test" >> /tmp/a/c
mkdir -p /tmp/a/d/e
echo "blah" >> /tmp/a/d/e/f #only exists here
mkdir -p /tmp/q/b
echo "testing" >> /tmp/q/c #/tmp/a/c shouldnt match
mkdir -p /tmp/q/d/e
echo "blah" >> /tmp/q/d/e/g #only exists here
diff -rq /tmp/a /tmp/q

results in :

Files /tmp/a/c and /tmp/q/c differ
Only in /tmp/a/d/e: f
Only in /tmp/q/d/e: g