I'm comparing two very large filesystems (to do with a migration) and diff -qr was great but now since the users have been using the new location the files have changed. I there a way to use diff, grep or anything else to compare only if the file exists, ie: ignore the fact that files differ. By latest diff has a lot of: Only in /dir1/myFile Only in /dir2/myFile In it. is there either an easy way to use grep to show only the files that don't exist at all in dir2 that do exist in dir1 or do something similar with diff.
问问题
343 次
3 回答
1
you can use:
tree /path/to/dir1 > out1
tree /path/to/dir2 > out2
diff out1 out2 | grep ">"
but i find beyond compare more suitable for a job like this.
于 2012-10-02T08:35:52.057 回答
1
You may also use the command comm
comm -1 -2 <(ls /path_to_dir-1/) <(ls /path_to_dir-2/)
Check the following link for additional info:
于 2012-10-02T08:44:33.883 回答
0
The one liners above are great, but this bash script allows you more customization: can change -e
to ! -e
or skip certain files.
for f in $(find old/ -type f) ;
do
if [ -e "new/${f}" ] ;
then
echo "${f} exists" ;
fi ;
done
于 2012-10-02T08:57:10.880 回答