|
Home > Archive > Unix Programming > September 2004 > Program to compare two directory trees
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Program to compare two directory trees
|
|
| Norm Dresner 2004-09-23, 5:54 pm |
| In the distant past I wrote my own program to recursively traverse two
parallel directory trees (each at arbitrary depth from the root) and list
the differences between them. The program used (IIRC) stat() to get file
sizes and dates and printed a line on the output for each mismatch.
I find myself needing something like this again, but this time I don't care
about the sizes or dates, just the (non-)existence of the files. Before I
reinvent the wheel, is there a (pseudo) standard utility available that will
do this. I'm less likely to make stupid errors that would invalidate my
explorations if I can use a pre-tested program than if I have to study and
try to understand code I wrote over a decade ago.
TIA
Norm
| |
| Larry I Smith 2004-09-23, 5:54 pm |
| Norm Dresner wrote:
> In the distant past I wrote my own program to recursively traverse two
> parallel directory trees (each at arbitrary depth from the root) and list
> the differences between them. The program used (IIRC) stat() to get file
> sizes and dates and printed a line on the output for each mismatch.
>
> I find myself needing something like this again, but this time I don't care
> about the sizes or dates, just the (non-)existence of the files. Before I
> reinvent the wheel, is there a (pseudo) standard utility available that will
> do this. I'm less likely to make stupid errors that would invalidate my
> explorations if I can use a pre-tested program than if I have to study and
> try to understand code I wrote over a decade ago.
>
> TIA
> Norm
>
'diff' should do it. See:
info diff
It'll recurse 2 dir trees. It can display details of the
diffs, or it can merely display match/nomatch. There are many
options. Check the 'info' pages....
Regards,
Larry
--
Anti-spam address, change each 'X' to '.' to reply directly.
| |
| Pascal Bourguignon 2004-09-23, 5:54 pm |
|
"Norm Dresner" <ndrez@att.net> writes:
> In the distant past I wrote my own program to recursively traverse two
> parallel directory trees (each at arbitrary depth from the root) and list
> the differences between them. The program used (IIRC) stat() to get file
> sizes and dates and printed a line on the output for each mismatch.
>
> I find myself needing something like this again, but this time I don't care
> about the sizes or dates, just the (non-)existence of the files. Before I
> reinvent the wheel, is there a (pseudo) standard utility available that will
> do this. I'm less likely to make stupid errors that would invalidate my
> explorations if I can use a pre-tested program than if I have to study and
> try to understand code I wrote over a decade ago.
find $dir1 -print | sort > /tmp/dir1
find $dir2 -print | sort > /tmp/dir2
diff /tmp/dir1 /tmp/dir2
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.
| |
| John L 2004-09-23, 5:54 pm |
|
"Norm Dresner" <ndrez@att.net> wrote in message news:9nF4d.419949$OB3.225499@bgtnsc05-news.ops.worldnet.att.net...
> In the distant past I wrote my own program to recursively traverse two
> parallel directory trees (each at arbitrary depth from the root) and list
> the differences between them. The program used (IIRC) stat() to get file
> sizes and dates and printed a line on the output for each mismatch.
>
> I find myself needing something like this again, but this time I don't care
> about the sizes or dates, just the (non-)existence of the files. Before I
> reinvent the wheel, is there a (pseudo) standard utility available that will
> do this. I'm less likely to make stupid errors that would invalidate my
> explorations if I can use a pre-tested program than if I have to study and
> try to understand code I wrote over a decade ago.
>
dircmp, at least on Solaris.
rsync and rdist (with the appropriate arguments).
--
John.
| |
| James Antill 2004-09-24, 5:51 pm |
| On Thu, 23 Sep 2004 19:21:41 +0000, Norm Dresner wrote:
> In the distant past I wrote my own program to recursively traverse two
> parallel directory trees (each at arbitrary depth from the root) and list
> the differences between them. The program used (IIRC) stat() to get file
> sizes and dates and printed a line on the output for each mismatch.
>
> I find myself needing something like this again, but this time I don't care
> about the sizes or dates, just the (non-)existence of the files. Before I
> reinvent the wheel, is there a (pseudo) standard utility available that will
> do this. I'm less likely to make stupid errors that would invalidate my
> explorations if I can use a pre-tested program than if I have to study and
> try to understand code I wrote over a decade ago.
diff -qru <dir> <dir>
--
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/
| |
| Norm Dresner 2004-09-24, 5:51 pm |
| "James Antill" <james-netnews@and.org> wrote in message
news:pan.2004.09.24.17.57.29.757033@and.org...
> On Thu, 23 Sep 2004 19:21:41 +0000, Norm Dresner wrote:
>
list[vbcol=seagreen]
file[vbcol=seagreen]
care[vbcol=seagreen]
I[vbcol=seagreen]
will[vbcol=seagreen]
and[vbcol=seagreen]
>
> diff -qru <dir> <dir>
Yeah, several people have pointed out that modern versions of diff will do
that. The original program was written back in the '80s for a VAX running a
UNIX-like OS. Ah, progress ...
Thanks to all who answered.
Norm
| |
| Peter Ammon 2004-09-24, 5:51 pm |
| Norm Dresner wrote:
> "James Antill" <james-netnews@and.org> wrote in message
> news:pan.2004.09.24.17.57.29.757033@and.org...
>
>
> list
>
>
> file
>
>
> care
>
>
> I
>
>
> will
>
>
> and
>
>
>
> Yeah, several people have pointed out that modern versions of diff will do
> that. The original program was written back in the '80s for a VAX running a
> UNIX-like OS. Ah, progress ...
>
> Thanks to all who answered.
>
> Norm
Sorry, I don't see the original response, which is why I'm replying
here. My second reaction to this was diff as well, but won't diff
report differences in the files' contents, not merely the existence of
the files? The OP appears to want different files with the same name to
be considered the same, and AFAIK diff cannot do that.
My first reaction was to use find to enumerate the directory contents in
each directory, and then diff to compare them.
-Peter
| |
| Larry I Smith 2004-09-24, 8:49 pm |
| Peter Ammon wrote:
> Norm Dresner wrote:
>
>
>
> Sorry, I don't see the original response, which is why I'm replying
> here. My second reaction to this was diff as well, but won't diff
> report differences in the files' contents, not merely the existence of
> the files? The OP appears to want different files with the same name to
> be considered the same, and AFAIK diff cannot do that.
>
> My first reaction was to use find to enumerate the directory contents in
> each directory, and then diff to compare them.
>
> -Peter
Diff has many options. Several cause it to merely say that
a file differs in the two dirs, or that a file is only in one
of the dirs. Given none of these options, it will display
the diffs of the file contents. Here's one possible example:
diff --brief --recursive dir1 dir2
See 'info diff' for additional options (there are about 50
options available).
Regards,
Larry
--
Anti-spam address, change each 'X' to '.' to reply directly.
| |
| Kevin Rodgers 2004-09-27, 5:55 pm |
| Norm Dresner wrote:
> Yeah, several people have pointed out that modern versions of diff will do
> that. The original program was written back in the '80s for a VAX running a
> UNIX-like OS. Ah, progress ...
It was the '70s (not the '80s), for Unix (not "a UNIX-like OS"), on the
PDP (not a VAX).
http://encyclozine.com/Diff
--
Kevin Rodgers
| |
| Norm Dresner 2004-09-27, 5:55 pm |
| "Kevin Rodgers" <ihs_4664@yahoo.com> wrote in message
news:41584D13.508@yahoo.com...
> Norm Dresner wrote:
do[vbcol=seagreen]
running a[vbcol=seagreen]
>
> It was the '70s (not the '80s), for Unix (not "a UNIX-like OS"), on the
> PDP (not a VAX).
>
> http://encyclozine.com/Diff
>
Sorry, I didn't make myself clear -- I wasn't talking about diff but about
my own program which I did write in the '80s.
Norm
|
|
|
|
|