|
DirComp - Utility to compare two directories |
The utility DirComp compares two directories (and - if specified - their subdirectories), where the comparison can be done both by existence and by date (of change; from now on called "timestamp") or contents.
The number of differnt files is returned 1 (unless other specified).
Syntax:
DirComp [<Option(s)> ...] Originaldir Comparedir DirComp --daemon[[=]<port>] DirComp --server[[=]<port>]
with following meaning of parameters:
Option ....... Options to control the program (Case-sensitiv!) -s, --recursive ....... Recursive compare of subdirectories -E, --rec-equal ....... Recurse into subdirectories found in both dirs -n, --no-changed ...... Suppress younger and deleted files -N, --existing ........ Suppress new and deleted files -e, --equal ........... Shows equal files -d, --show-dirs ....... Show directories if their timestamps differs -v, --verbose ......... Shows files with their timestamps -H, --hidden .......... Compare also hidden files -c, --compare ......... Compare contents of (differing) files (if readable) -C, --force-compare ... Compare contents of (all) files (if readable) -i, --include ......... <Filespec>: Restrict compare to passed filespecifiation -x, --exclude ......... <Filespec>: Exclude specified files -I, --include-dirs .... <Dirspec>: Restrict compare to the specified directories -X, --exclude-dirs .... <Dirpec>: Exclude specified directories -t, --begin-time ...... <Datum>: Lower border of the time-range for compare -T, --end-time ........ <Datum>: Upper border of the time-range for compare -V, --version ......... Output version info -q, --quiet ........... Quiet mode: suppresses any unneccesary output -Q, --silent .......... Silent mode; suppresses any output (for batch-processing) -a, --action .......... <Action>: Perform specified action on differing files -A .................... <Change-ID>[<Action>]: Perform action on selected files -S, --server .......... [<port>]: Start as server (run in foreground) listening at port -D, --deamon .......... [<port>]: Start as server (run as deamon) listening at port -r, --ret-changed ..... Return number of changed files -R, --ret-new ......... Return number of new or deleted files -h, -?, --help ........ Display help and exit Originaldir ... Basis of the compare (original directory) Comparedir .... Directory with which to compare
The call of
DirComp -d Test1 Test2
could result in (for example)
Older : DirComp.cpp New : DynArray.h Younger: Test New : Another Deleted: Other Deleted: DirComp.Mak
The option s would also compare the subdirectories Test, Other and Another. Similar is the option option E, which only compares subdirectories which exist in both directories.
The option n would suppress the Younger/Older-lines; similar to the option N, which would suppress the New/Deleted-lines.
To view even equal (means same name (and timestamp and contents, if specified)) files the option e must be specified. This could result in an output like this:
Equal : DirComp.h
If the option d would not be specified, the line "Younger: Test " would not be displayed (this is default, because Test is a directory whose time-differences do normally not matter).
The option v displays the timestamp of every different file(s). If the comparative file exists in both directories the timestamp of both files are shown.
The option c compares the contents of files with different timestamps (and same size) and lists them only if this differs too.
The option C compares the contents of files independent of their timestamp. Differing files (with the same timestamp) produce following output:
Differs: DirComp.cpp
Hidden files can be included into the comparison with the option H. Which files that are depends on the operating-system; on *NIX-systems it are files starting with a dot (.), other OS (like OS/2 or DOS and its graphical bug-collection) have a special file-attribute for that.
The option i restricts the compare on files (not directories!), which matches the passed file-specification. The wildcards asterisk (*) (means "any zero or more characters in this position") and the question mark (?) (matches any single character) are supported. By specifiying characters or ranges of charachters in square brackets (([) and (])) filenames can be restrict more specifically. This selection can be inverted by specifying the caret (^) as first character in the list.
Analogue to this the option x excludes files from comparing.
File-specifications can be combined by separating them with the path-seperation character of the OS (the colon (:) in *NIX or the semicolon (;) in OS/2, DOS and Windoze) or by using the respective option again.
e.g. -i*.cpp -i *.h -x*[^1-9].cpp:[A-EXYZ]*.cpp for *NIX e.g. -i*.cpp -i *.h -x*[^1-9].cpp;[A-EXYZ]*.cpp for OS/2, DOS
These options are checked from right to left, so write the more general file-specifictaion first; if no include-option (-i) is specified, a leading -i* is assumed.
Similar to the last two options I and X restricts the comparison to the specified subdirectories.
Wildcards are supported in more levels for directories; e.g -I*/?O includes all subdirectories in the second level, which ends with an O at the second position; -XLinux/* does not compare all subdirectories from Linux.
If (at least) one of the above options is specified, subdirectories are compared automatically (even if the option s was not specified; I guess that makes kind of sense).
The options t und T restricts the comparison to files which are in the specified date-range (inclusive the borders); t specifies the lower, and T the upper border.
These options expects a date (in format D.M.YYYY-h:m:s) as parameter, where the single values can be separated by any non-numeric characters. Note: Leading Zeros (0) are not allowed!
Note: If there are two files with the same name, where only one is inside this range it is reported as New (or Deleted); files outside this range does not exist (at least for DirComp)!
The option V displays additional information to the programm (like date of the compilation; information about the author) and a more detailed description while displaying the help.
The option q suppresses any additional lines (execpt - of course - for the help) and restricts therefore the output to the file-information (according to the other options). This is usefull when processing the output automatically.
For batch-processing usefull are the options r, R and Q. The last suppresses every output of the programm; the first returns the number of changed (not new or deleted to be exact) and the second the number of new or deleted files (the default-return value are all differing files)1.
The options a and A allow to specify actions, which should be performed to the differing files. In the parameter for the action the following place-holders are substituted:
Place-holder | Is replaced with |
---|---|
{OP} | Path of the original file |
{OF} | Path and name of the original file |
{CP} | Path of the comparative file |
{CF} | Path and name of the comparative file |
The option A needs also a Change-ID, which specifies for what kind of files the action shall be performed. Possible values are (these values can be ORed together; geek-thinking at its best, but - after all - this tool is for programmers and the porn-collectors shall find other ways to synchronize their picture-galleries):
Change-ID | Associated files |
---|---|
1 | Younger files |
2 | Older files |
4 | Differing files (same timestamp but differing contents according to option C) |
8 | Equal files |
16 | Deleted files |
32 | New files |
If minus (-) is specified as action (or none for A) no action is performed (to update the original-directory you could use the following (equivalent) commands):
DirComp "-acp {CF} {OP}" -A26 . .. DirComp "-A37cp {CF} {OP} +1" . ..
Directories can also be compared over a network. To do so the utility must be started as server (option S) or daemon (option D) on the remote Computer. The directory is specified as <server>:<directory>[:<port>]. An example would be:
DirComp /usr/local/src/DirComp prod:/usr/local/DirComp:4711
On the server prod the utility must be started as follows:
DirComp -D 4711
To show occuring errors (and not to only write them into the system-log), the option D could be replaced with S. The default-port for the communication is 31336.
Use this feature with care as it might provide an attacker with information about your directory-structure and the installed programs! That's exactly the reason why you must enable it at compile-time.
Mail comments |