Memo For Diff Options

Compare files under the specified directory and display only file names

diff -qr /home/vagrant/example1 /home/vagrant/example2

Compare ignoring newline spaces and newline codes

cd /home/vagrant/
diff -Bw --strip-trailing-cr example1.txt example2.txt

Display only the differences side by side

cd /home/vagrant/
diff -y example1.txt example2.txt | grep "|\|<"

Side-by-side comparison (vimdiff)

⚠️ Vim must be installed

#Option 1
cd /home/vagrant/
vimdiff example1.txt example2.txt
#Option 2
cd /home/vagrant/
vim -d example1.txt example2.txt

Diff Options

Compare by directory

diff -r /home/vagrant/example1 /home/vagrant/example2

Show file name only

diff -q /home/vagrant/example1 /home/vagrant/example2

Ignore newlines

diff -B example1.txt example2.txt

Ignore whitespace

diff -w example1.txt example2.txt

Ignore newline code

diff — strip-trailing-cr example1.txt example2.txt

Ignore case

diff -i example1.txt example2.txt

Side by side comparison

diff -y example1.txt example2.txt

 by the author.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

Maciej

623 Followers

DevOps Consultant. I’m strongly focused on automation, security, and reliability.