Memo For Diff Options

Maciej
Aug 23, 2022

--

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

--

--

Maciej

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