PDA

View Full Version : [SOLVED] comparison of directory contents



mvalviar
November 12th, 2009, 07:51 AM
I've been trying to figure this out by myself but to no avail. How do I list files in one dir that is also found on another dir. ie:

dir1 dir2
| |
+file1 +file1
+file2 +file2
+file3
`file4

$<some command> dir dir2
file1
file2

ghostdog74
November 12th, 2009, 08:01 AM
hardcore method and assuming you are not traversing directories


#!/bin/bash
ls /home/path2| awk 'BEGIN{
cmd="ls /home/path1"
while ( (cmd|getline f)>0) {
files[f]
}
close(cmd)
}
($0 in files){
print "found: "$0
}'



Of course, the more simpler method is to use diff. check its man page for usage

slakkie
November 12th, 2009, 08:17 AM
I would go for diff:

diff -qr /dir1 /dir2

mvalviar
November 12th, 2009, 06:54 PM
Thanks! diff -qr dir1 dir|grep differ and I got the output I was looking for.