We're an ISO27001:2013 Certified Supplier


Sometimes we want to compare two directory trees – maybe one is from another system or a backup, and you want to see how they differ. The diff command has a couple of qualifiers that can help:

  • -r recurses subdirectories
  • -q only reports that files are different rather than displaying the differences.

Here’s a typical Apache configuration directory tree from a Debian-based system:

$ tree -d apache2
├── conf-available
├── conf.d
├── conf-enabled
├── mods-available
├── mods-enabled
├── sites-available
└── sites-enabled

In that directory tree, there are 218 files:

$ ls apache2 | wc -l

Let’s assume we have a backup of that directory in apache2-backup, and we want to see what has changed since that backup was taken. We want to see:

  • files that have been added
  • files that have been removed
  • files that have changed

We don’t need to look at all 218 file to find those differences. Instead, we can use diff:

$ diff -rq apache2 apache2-backup
Files apache2/apache2.conf and apache2-backup/apache2.conf differ
Only in apache2-backup/sites-enabled: wiki.example.com.conf

Could this Linux Tip be improved? Let us know in the comments below.

Leave a Reply

Your email address will not be published.

Secure. Reliable. Scalable.

If that doesn't describe your current Linux systems, check out our FREE Linux Survival Guide to help you get your systems up to scratch today!
  • This field is for validation purposes and should be left unchanged.