Mokus Asked: 2011-06-17 01:30:17 +0800 CST2011-06-17 01:30:17 +0800 CST 2011-06-17 01:30:17 +0800 CST Compare two folder content 772 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. ubuntu diff 3 Answers Voted Best Answer Janne Pikkarainen 2011-06-17T01:41:49+08:002011-06-17T01:41:49+08:00 At least you can use diff -s dir otherdir | grep -v "Only in" symcbean 2011-06-17T04:41:44+08:002011-06-17T04:41:44+08:00 #!/bin/bash ls $1 >/tmp/$$1 ls $2 >/tmp/$$2 join /tmp/$$1 /tmp/$$2 rm /tmp/$$1 rm /tmp/$$2 initall 2011-06-17T01:43:51+08:002011-06-17T01:43:51+08:00 #!/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
At least you can use
diff -s dir otherdir | grep -v "Only in"