Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I compare two folder content under linux. I'm using diff but I want to display only the files with the same names.

share|improve this question
up vote 4 down vote accepted

At least you can use

diff -s dir otherdir | grep -v "Only in"

share|improve this answer

ls $1 >/tmp/$$1
ls $2 >/tmp/$$2

join /tmp/$$1 /tmp/$$2

rm /tmp/$$1
rm /tmp/$$2
share|improve this answer

f1=$(find "$D1" -type f)
f2=$(find "$D2" -type f)

for i in $f1; do 
    echo $f2 | grep $(basename $i) >/dev/null && echo $i
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.