Take the 2-minute tour ×
Server Fault is a question and answer site for 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

3 Answers 3

up vote 4 down vote accepted

At least you can use

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

share|improve this answer
#!/bin/bash

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

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

rm /tmp/$$1
rm /tmp/$$2
share|improve this answer
#!/bin/bash

D1=/tmp/1
D2=/tmp/2
f1=$(find "$D1" -type f)
f2=$(find "$D2" -type f)

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

Your Answer

 
discard

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.