home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 16.21 Finding All Directories with the Same Name Chapter 16
Where Did I Put That?
Next: 16.23 Comparing Filenames in Two Directory Trees
 

16.22 Comparing Two Directory Trees with dircmp

You have an original directory. You copy the files in it to another directory, edit some of them, and add a few others. Later, you want to know the differences between the two directories. If your system's diff (28.1 ) has a -r (recursive) option, you can use that. System V has dircmp . The output of dircmp is formatted with pr (43.7 ) ; you get 66-line-long pages with headings:

% dircmp a b



Sep 16 09:26 1991  a only and b only Page 1

./foo.tmp                                   ./defs.h
   ...

Sep 16 09:26 1991  Comparison of a b Page 1

directory   .
same        ./Makefile
directory   ./data
same        ./data/test1
same        ./data/test2
   ...

different   ./pqp.help
same        ./pqs.help
   ...

In the a only and b only listing, files only in the first directory are in the first column and files only in the second directory are in the second column. The Comparison of a b listing compares files that are in both directories. The comparison is recursive - if there are any subdirectories, dircmp checks those, too.

The dircmp -s option stops the "identical file" messages. Use -d to run diff on files that are different; dircmp prints a new page for each diff it runs:

% dircmp -d -s a b


Sep 16 09:35 1991  a only and b only Page 1
   ...
Sep 16 09:35 1991  Comparison of a b Page 1
   ...
Sep 16 09:35 1991  diff of ./pqp.help in a and b Page 1

3c3,4
< -#    "Only this printer"... 'pqp -3' would print on #3.
--
> -#    "Only this printer"... 'pqp -3' would print only on #3;
>       other printer queues will be held.
   ...

The designers assumed you'd want to send the output to a printer. I usually read it on my screen with the less (25.4 ) pager and its -s option, which squeezes out the multiple blank lines. If you don't have less or more -s , try piping the output through cat -s (25.10 ) or a sed filter (34.18 ) .

- JP


Previous: 16.21 Finding All Directories with the Same Name UNIX Power Tools Next: 16.23 Comparing Filenames in Two Directory Trees
16.21 Finding All Directories with the Same Name Book Index 16.23 Comparing Filenames in Two Directory Trees

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System