Skip to content

Instantly share code, notes, and snippets.

@pudgereyem
Created March 31, 2014 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pudgereyem/9888148 to your computer and use it in GitHub Desktop.
Save pudgereyem/9888148 to your computer and use it in GitHub Desktop.
SHELL: Explore the difference between files and folder structures with diff
# From http://hints.macworld.com/article.php?story=20070408062023352
`diff` helps you explore the difference between files and folder structures in Unix. Really good.
`diff -qr dirA dirB | grep -v -e 'DS_Store' -e 'Thumbs' | sort > diffs.txt`
---
> As mentioned in other hints, diff can not only compare two files, it can, by using the -r option, walk entire directory trees, recursively checking differences between subdirectories and files that occur at comparable points in each tree. The trick is to use the -q option to suppress line-by-line comparisons in files that differ:
`diff -rq dirA dirB`
> This command will provide a nice list of files that occur in dirA but not in dirB, files that occur in dirB, but not in dirA, and files that differ between dirA and dirB. Pipe the output through grep to remove mention of uninteresting files, and sort to tidy it up, e.g.:
`diff -qr dirA dirB | grep -v -e 'DS_Store' -e 'Thumbs' | sort > diffs.txt`
> This list gives me a good feel for the big picture before I start overwriting things: which files or subdirectories can be deleted, which can be synced (and in which direction) using rsync, and which should be carefully checked before replacing, in case changes need to be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment