Content-type: text/html Manpage of COMPDIR


Section: Misc. Reference Manual Pages (1L)
Updated: 16 November 1988


compdir - compare two directories  


compdir [ -a ] [ -h ] [ -l ] [ -m ] [ -s ] [ -t ] [ -2 ] [ -X pat... ] dir1 dir2  


Compdir recursively compares the files in the two directories dir1 and dir2. By default, it compares the contents of the files and prints nothing if they compare equal; else it prints
directory: path/filename
when filename is a directory under one path but not under the other path;
differ: path/filename
when filename is newer under the printed path than under the other directory;
only: path/filename
when filename exists in one path only.

Plain compdir is about the same speed as diff -r, but compdir -m, which compares modification times instead of contents, is much faster than diff.  


Compare all files, including files beginning with a dot (.). The default action is to ignore such files.
Summarize the options and exit.
Set stdout to be line buffered.
Compare modification times instead of contents. This is much faster than comparing the contents. It's useful if you expect the directories' files to have the same dates, such as would be the case if you created a copy using tar or cp -rp.
When both files are the same, print lines like
same: path/filename
Normally only non-matches are printed.
Compare contents of files, and if they are the same touch the modification time on the newer file to have the same time as the older file. This is useful if you have created a backup directory but didn't preserve dates. In that case, you can do compdir -t dir1 dir2 once, and thereafter you can more quickly compare the directories by looking at file modification times instead of the file contents.
Print both filenames, instead of just the newer, when files differ or when both are the same, but just the one filename for ``only'' files.
Print both filenames, instead of just the newer, for all compared files. This makes it easy to edit the output into shell commands that, say, copy the newer file to the older. The only or newer file is printed first; the missing or older filename is printed second.
-X pat...
Exclude patterns. Any file in dir1 that matches the sh(1)-style wildcard pattern specified by pat is ignored in comparisons. More than one pattern may be given; it's often necessary to quote the pattern to prevent interpretation by the shell. Note: slashes (/) are treated as ordinary characters when matching names.


The following command
% compdir -X "*.o" "*.a" mydir mydir.backup
compares the contents of the files in mydir and mydir.backup, ignoring object files and libraries.  


William Deich