3

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.

Mokus
  • 412
  • 1
  • 11
  • 20

3 Answers3

5

At least you can use

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

Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81
1
#!/bin/bash

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

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

rm /tmp/$$1
rm /tmp/$$2
symcbean
  • 21,009
  • 1
  • 31
  • 52
0
#!/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
initall
  • 2,325
  • 3
  • 18
  • 19