Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Last active December 24, 2015 23:49
Show Gist options
  • Save alancoleman/6883472 to your computer and use it in GitHub Desktop.
Save alancoleman/6883472 to your computer and use it in GitHub Desktop.
diff commands for shell
# The difference between two folders
diff folder_1 folder_2
# The difference between two files
diff file_1.txt file_2.txt
# The difference between two folders recursive
diff -r folder_1 folder_2
# Create a patch file from a diff
diff file_1.txt file_2.txt > example.patch
# Create a patch file from a diff in unified format ( Denotes what file to be patched in a header)
diff -u file_1.txt file_2.txt > example.patch
# Patch a file
patch file_1.txt < example.patch
# Patch a file form a patch in unified format
patch < example.patch
# Remove a patch
patch file_1.txt -R < example.patch
# Flags
# Recursive, compares every corresponding pair of files in the directory trees, as many levels deep as they go
diff --recursive folder_1 folder_2
# or
diff -r folder_1 folder_2
# Report identical files
diff --report-identical-files folder_1 folder_2
# or
diff -s folder_1 folder_2
# Exclude. This option ignores any files or subdirectories whose base names match the shell pattern
diff --exclude=pattern folder_1 folder_2
# or
diff -x pattern folder_1 folder_2
# http://www.gnu.org/software/diffutils/manual/html_node/index.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment