Comparing the contents of 2 directories


WARNING: Please read before continuing ▼

Difficulty: Easy
Time: Varies
Last Updated: 9th November 2009
Applies to: OS X, and Linux

Sometimes, you can end up with multiple copies of a directory from different times. If the number of files is small, then comparing the contents is easy. With large directories, telling the difference between them can be nearly impossible.

diff is a tool for comparing two sources of data. The data to be compared, like most unix programs, can come from anywhere. Typically, it is used to compare individual files, and in the software world, list the differences between two revisions to create a patch.

It also has a mode of operation, whereby it can be used to compare two directories.

To use diff in this fasion, the command is:

1
diff -q /path/to/folder/1/ /path/to/folder/2/

A comparison on very large folders may take some time, but providing that the folders aren’t too different, you will get some output like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Defiant:~ adam$ diff -q ~/Folder1 ~/Folder2
Files /Users/adam/Folder1/.DS_Store and /Users/adam/Folder2/.DS_Store differ
Common subdirectories: /Users/adam/Folder1/Custom Music and /Users/adam/Folder2/Custom Music
Common subdirectories: /Users/adam/Folder1/DCBackup and /Users/adam/Folder2/DCBackup
Common subdirectories: /Users/adam/Folder1/DCCache and /Users/adam/Folder2/DCCache
Files /Users/adam/Folder1/DeviceConfig.log and /Users/adam/Folder2/DeviceConfig.log differ
Common subdirectories: /Users/adam/Folder1/Downloads and /Users/adam/Folder2/Downloads
Only in /Users/adam/Folder1: Exports
Common subdirectories: /Users/adam/Folder1/InstalledWorlds and /Users/adam/Folder2/InstalledWorlds
Common subdirectories: /Users/adam/Folder1/Library and /Users/adam/Folder2/Library
Common subdirectories: /Users/adam/Folder1/Saves and /Users/adam/Folder2/Saves
Files /Users/adam/Folder1/Sims3Logs.xml and /Users/adam/Folder2/Sims3Logs.xml differ
Common subdirectories: /Users/adam/Folder1/Thumbnails and /Users/adam/Folder2/Thumbnails
Common subdirectories: /Users/adam/Folder1/WorldCaches and /Users/adam/Folder2/WorldCaches

From this, it is easy to see where the changes lie. It will tell you any matching folders, any missing folders or files, and if the contents of any file do not match.

, , , ,

  1. No comments yet.
(will not be published)

Powered by WP Hashcash


Technical Procedures is Digg proof thanks to caching by WP Super Cache