comparing two directory structures

comparing two directory structures

Oleg Goldshmidt pub at goldshmidt.org
Sat Sep 4 13:08:07 IDT 2010


Gabor Szabo <szabgab at gmail.com> writes:

> hi,
>
> I guess there is an obvious command for this, I just don't know it.
>
> How can I compare two directory structures if the content is the same
> *disregarding*
> actual file content, or comparing that only if the file names and
> sizes are the same?
>
> As I understand diff -r  would do it but it would also compare files
> line by line.
>
> As these are images and movies, I don't want to compare them line by
> line or event byte by byte.
> As a first approximation I only want to list files that exists in one
> directory but not in the other
> or when the files have different size.

What about adding -q or --brief to "diff -r"? Will that not do the trick
for you?

If diff options don't do the job for whatever reason then, given that
you are only interested in file names and sizes, maybe some cheating
(compare directory listings rather than files themselves) shell
sorcery like (bash syntax)

function shortlist() { /bin/ls -l $1 | /bin/awk '{print $5 " " $8}'; }

function shortdiff() { /usr/bin/diff -u <(shortlist $1) <(shortlist $2); }

or similar will be good enough? For more generality, you may try

function shortlist() { 
  /bin/find $1 -type f -ls | /bin/awk '{print $7 " " $NF}'
}

instead of the above.

-- 
Oleg Goldshmidt | pub at goldshmidt.org



More information about the Linux-il mailing list