0

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.

3 Answers 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.

1
  • Sorry I didn't mention I was working on a mac, but this looks good. I'm not sure about the ">" but you've given me enough cheers. Oct 2, 2012 at 9:37
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:

http://nixtricks.wordpress.com/2010/01/11/unix-compare-the-contents-of-two-directories-in-the-command-line/

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.