Compare Directories and Files with Diff

Sometimes working with a directory full of subdirectories and files you need to compare the directories and files to another version of the files.  This comes in extremely useful when restoring a hacked website.  To do this you need to have the old copy and the current copy in two different directories on your system.  Then run the command below replacing DIR1 and DIR2 with the directoires you would like to compare.  This works through the entire directory because of the -r option which stand for recursive.  The -q option suppresses the entire output and only outputs the files the differ.

diff -rq DIR1 DIR2

 

Your output should look something like this

CBrownMac:Desktop Chris$ diff -rq csiconfig2 csiconfig_2013-01-29_11-21
Only in csiconfig2: Log.00:0C:42:F1:17:DC
Only in csiconfig2: Log.00:0C:42:F1:17:E0
Only in csiconfig2: Log.00:0C:42:F5:CE:FC
Only in csiconfig2: Log.00:0C:42:F5:CF:00
Only in csiconfig2: Log.00:0C:42:F5:CF:02
Only in csiconfig2: Log.00:0C:42:F6:DD:68
Only in csiconfig2: Log.00:0C:42:F6:DD:6A
Only in csiconfig2: Log.00:0C:42:F6:DD:6C
Only in csiconfig_2013-01-29_11-21: Log.r-main-csi
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F1:17:DC
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F1:17:E0
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F5:CE:EC
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F5:CE:FC
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F5:CE:FE
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F5:CF:00
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F5:CF:02
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F6:DD:42
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F6:DD:5A
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F6:DD:68
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F6:DD:6A
Only in csiconfig_2013-01-29_11-21: Log.r-sub.00:0C:42:F6:DD:6C
Files csiconfig2/Makefile and csiconfig_2013-01-29_11-21/Makefile differ
Only in csiconfig2: Programmer-3.rcs
Only in csiconfig2: Programmer-4.rsc
Only in csiconfig2: Programmer-5.rsc
Only in csiconfig2: Programmer-6.rsc
Files csiconfig2/a-main and csiconfig_2013-01-29_11-21/a-main differ
Files csiconfig2/a-sub and csiconfig_2013-01-29_11-21/a-sub differ
Only in csiconfig_2013-01-29_11-21: b-main
Only in csiconfig_2013-01-29_11-21: b-sub
Only in csiconfig_2013-01-29_11-21: do-reset
Only in csiconfig2: programmer1.rsc
Only in csiconfig_2013-01-29_11-21: r-main
Only in csiconfig_2013-01-29_11-21: r-sub
Only in csiconfig2: reset
CBrownMac:Desktop Chris$

 

You can view other options for diff via

man diff

 

Leave a Reply

Your email address will not be published. Required fields are marked *