🖥️diff

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the diff command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                ██████╗ ██╗███████╗███████╗
#                ██╔══██╗██║██╔════╝██╔════╝
#                ██║  ██║██║█████╗  █████╗  
#                ██║  ██║██║██╔══╝  ██╔══╝  
#                ██████╔╝██║██║     ██║     
#                ╚═════╝ ╚═╝╚═╝     ╚═╝     

# To view the differences between two files:
diff -u version1 version2

# To view the differences between two directories:
diff -ur folder1/ folder2/

# To ignore the white spaces:
diff -ub version1 version2

# To ignore the blank lines:
diff -uB version1 version2

# To ignore the differences between uppercase and lowercase:
diff -ui version1 version2

# To report whether the files differ:
diff -q version1 version2

# To report whether the files are identical:
diff -s version1 version2

# To diff the output of two commands or scripts:
diff <(command1) <(command2)

# Generate a patch file from two files
diff -Naur version1 version2 > version.patch

#==============================#
# CMD DIFF
#==============================##==============================#
diff -0u <(ls $dir1) <(ssh localhost ls $dir2)

diff -e 
# produces an ed program. ed is the ancestor of sed.

diff -E or --ignore-tab-expansion
# The option -E or --ignore-tab-expansion tells diff to ignore the distinction between tabs and spaces.

diff -w or --ignore-all-space 
# The option -w or --ignore-all-space tells diff to ignore spaces in one line even where the corresponding line has none.

diff -i or --ignore-case
# The option -i or --ignore-case tells diff to do a case-insensitive comparison.

diff -q (or --brief).
# If you only want to know whether two files differ, not how they differ 

diff -w or --ignore-all-space
# The option -w or --ignore-all-space tells diff to ignore spaces in one line even where the corresponding line has none.

diff -w index.html bookexample/index.html 
# Use the -w option in diff to ignore differences in whitespace (tabs instead of spaces, etc.)

diff resumecode.py origcode.py | less -S
# Check how similar code submitted with a resume is to the original code you found online. :-(

diff <(grep = config.txt) <(grep = config.txt-new)
# Compare just the assignment lines of two config files that use = for value assignment.

diff <(openssl rsa -in my.key -modulus | grep Modulus) <(openssl x509 -in my.crt -modulus | grep Modulus)
# Check if cert was signed by key.

diff --unchanged-group-format='@@ %dn,%df %<' --old-group-format='' --new-group-format='' --changed-group-format='' a.txt b.txt
#  

diff3 
# compares three files line by line.

diff -E
# The option -E or --ignore-tab-expansion tells diff to ignore the distinction between tabs and spaces.

diff -rq dir1 dir2 
# compare folder contents and show the difference

diff -r dir1/ dir2/ | sed '/Binary\ files\ /d' >outputfile 
# Recursive directory compare - Compare files from two different directories recursively

diff <(ssh server1 "cat /etc/fstab") <(ssh server2 "cat /etc/fstab") 
# compare two files on two different servers without downloading them

diff <(grep = config.txt) <(grep = config.txt-new) 
# Compare just the assignment lines of two config files that use = for value assignment.

# This should also work, using bash redirection into diff
diff <(sort -k2 names1.txt) <(sort -k2 names2.txt) 

# compare folder contents and show the difference @climagic 
diff -rq dir1 dir2 

# Bestes Diff
diff -u --color --suppress-common-lines DATEI1 DATEI2

diff -u --suppress-common-lines --color rsyslog.conf rsyslog.conf.dpkg-dist

# Compare mysql db schema from two different servers
diff <(mysqldump -hsystem db_name --no-data --routines) <(mysqldump -hsystem2 db_name --no-data --routines) --side-by-side --suppress-common-lines --width=690 | more

# Compare (diff) vim-generated backup of a file with that file's current version.
diff~() { diff "$1"~ "$1"; }

# Check difference between two file directories recursively
diff <(tree /dir/one) <(tree /dir/two)

# show the difference
diff file1 file2 --side-by-side --suppress-common-lines

# same with color
colordiff file1 file2 --side-by-side --suppress-common-lines

# 
colordiff <(tree /dir/one) <(tree /dir/two)
colordiff --side-by-side --suppress-common-lines <(tree vonsalt/) <(tree vontuxtux/)

# Compare (diff) vim-generated backup of a file with that file's current version.
function mydiff~() { diff "$1"~ "$1"; }

#==============================##==============================#
# CMD diff						       #
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░