Patrick Ward words, code, and music

Diff Cheatsheet

This is a collection of useful diff commands that I’ve collected.

Diff of two directories?

I needed to determine the difference between files of two directories (i.e. which files are identical, which files are different, and which files exist only in that directory). The following command shows me a summary of both directories and how they differ.

diff -qrs dir1 dir2
  • -q: show only whether files differ (not the full text difference)
  • -r: recursively compare any subdirectories found
  • -s: report when two files are the same

Which gave me something similar to the following:

Files dir1/templates/about.blade.php and dir2/templates/about.blade.php are identical
Files dir1/templates/ads/zone1.blade.php and dir2/templates/ads/zone1.blade.php are identical
Files dir1/templates/category.blade.php and dir2/templates/category.blade.php differ
Files dir1/templates/contact-email.blade.php and dir2/templates/contact-email.blade.php differ
Only in dir1/templates: page-with-linked-image.blade.php
Only in dir2/templates/partials: content-linked-image.blade.php