Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hxmuller/660ce0b1757da7d5434e1a058e4e02bd to your computer and use it in GitHub Desktop.
Save hxmuller/660ce0b1757da7d5434e1a058e4e02bd to your computer and use it in GitHub Desktop.
find and remove duplicate files from the second of two directories
# modify directory1/ and directory2/ paths as appropriate
#
# diff - compare files line by line
# -s report when two files are the same
# -r recursively compare any subdirectories found
# sed - stream editor for filtering and transforming text
# -n suppress automatic printing of pattern space
# cut - remove sections from each line of files
# -f select only these fields
# -d use DELIM instead of TAB for field delimiter
# xargs - build and execute command lines from standard input
diff -sr directory1/ directory2/ | sed -n '/identical/p' | cut -f4 -d' ' | xargs rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment