|
Home > Archive > Unix Shell > May 2007 > Script to compare two directory structures
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 |
Script to compare two directory structures
|
|
| Generic Usenet Account 2007-05-11, 1:17 pm |
| We had a need to compare two directory structures to see if they are
identical (meaning if they have the same structure, same contents and
same versions of files). I wrote a shell script for this purpose
(posted to the comp.sources.d newsgroup). It works, but given my
scant knowledge of scripting, it is rather crude. I am looking for
something more professional and robust, perhaps using perl. Any help
would be appreciated.
Thanks,
Bhta
| |
| Ed Morton 2007-05-11, 1:17 pm |
| Generic Usenet Account wrote:
> We had a need to compare two directory structures to see if they are
> identical (meaning if they have the same structure, same contents and
> same versions of files). I wrote a shell script for this purpose
> (posted to the comp.sources.d newsgroup). It works, but given my
> scant knowledge of scripting, it is rather crude. I am looking for
> something more professional and robust, perhaps using perl. Any help
> would be appreciated.
>
> Thanks,
> Bhta
>
diff -r dir1 dir2
If that doesn't work for you, explain why.
Ed.
| |
| Generic Usenet Account 2007-05-11, 1:17 pm |
| On May 11, 10:14 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
> diff -r dir1 dir2
>
> If that doesn't work for you, explain why.
>
> Ed.
Sheepishly I must admit that you are absolutely right. Thanks for
pointing this out ----- you made me realize how I wasted a couple of
hours of precious time on a wild goose chase.
| |
| Generic Usenet Account 2007-05-16, 7:18 pm |
| On May 11, 10:14 am, Ed Morton <mor...@lsupcaemnt.com> wrote:
> Generic Usenet Account wrote:
>
>
> diff -r dir1 dir2
>
> If that doesn't work for you, explain why.
>
> Ed.
There is at least one situation where my extremely crude script works,
but diff -r dir1 dir2 does not. For example, the script will work
even if the two directory structures are not visible on the same
system e.g. one directory is on the build server while another
directory is on the test server, and there is no cross mounting
between the two.
Bhta
| |
| Kenny McCormack 2007-05-20, 7:21 pm |
| In article < g5ednYCG5bfQFdnbnZ2dnUVZ_oHinZ2d@comcast
.com>,
Ed Morton <morton@lsupcaemnt.com> wrote:
....
>diff -r dir1 dir2
>
>If that doesn't work for you, explain why.
>
> Ed.
From what I can tell, "diff -r" actually compares (performs the 'diff'
functionality on) every file that it encounters. That's not strictly
speaking the same as that which most people intuitively assume when they
think of comparing directory structures.
What I am getting at is that what "most people intuitively assume when
they think of comparing directory structures" is comparing things at the
time-stamp level, not at the file contents level. The implications of
this are:
1) That comparing byte for byte is time-intensive (and usually
unnecessary)
2) That, especially on non-Unix systems, performing the 'diff'
functionality on binary files is not exactly a well-defined
operation.
Therefore, it would still be nice to have a Unix-based util that is
more akin to the sorts of things that many of us are familiar with on,
e.g., the MS Windows platform.
| |
| Jim Gibson 2007-05-21, 7:26 pm |
| In article <f2qg7g$e3e$1@news.xmission.com>, Kenny McCormack
<gazelle@xmission.xmission.com> wrote:
> In article < g5ednYCG5bfQFdnbnZ2dnUVZ_oHinZ2d@comcast
.com>,
> Ed Morton <morton@lsupcaemnt.com> wrote:
> ...
>
> From what I can tell, "diff -r" actually compares (performs the 'diff'
> functionality on) every file that it encounters. That's not strictly
> speaking the same as that which most people intuitively assume when they
> think of comparing directory structures.
>
> What I am getting at is that what "most people intuitively assume when
> they think of comparing directory structures" is comparing things at the
> time-stamp level, not at the file contents level. The implications of
> this are:
> 1) That comparing byte for byte is time-intensive (and usually
> unnecessary)
> 2) That, especially on non-Unix systems, performing the 'diff'
> functionality on binary files is not exactly a well-defined
> operation.
>
> Therefore, it would still be nice to have a Unix-based util that is
> more akin to the sorts of things that many of us are familiar with on,
> e.g., the MS Windows platform.
>
I am not familiar with utilities to compare directory structures on the
MS Windows platform, but were I to write a program to compare directory
structures (not file contents), I would use the File::Find module to
recursively get file names in each directory tree, the stat function to
get the modification times, and hashes to save and compare the
resulting data.
Good luck!
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
| |
| Josef Moellers 2007-05-22, 7:18 am |
| Jim Gibson wrote:
> I am not familiar with utilities to compare directory structures on the=
> MS Windows platform, but were I to write a program to compare directory=
> structures (not file contents), I would use the File::Find module to
> recursively get file names in each directory tree, the stat function to=
> get the modification times, and hashes to save and compare the
> resulting data.
As for the hashes (as in checksums), I'd use the Digest::MD5 module:
use File::Find to build a (Perl-)hash mapping pathnames to=20
node-information, constructing the latter from stat() and md5_hex().
If the number of entries is huge and memory is tight, you could write=20
this information for both trees to a file and then compare the contents=20
of these files.
Josef
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
|
|
|
|
|