Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 4 down vote accepted

At least you can use

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

share|improve this answer
add comment

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

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

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

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
add comment

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.