FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 10-23-2008, 01:53 PM
Bowie Bailey
 
Default compare directories

David Hlácik wrote:
> Hello guys,
>
> I have two mirrors. I need to compare files and directories on both
> mirrors and as a result print list of those which are missing on
> mirror 2
>
> What i did
>
> find /data > find.mirror1
>
> find /data > find.mirror2
>
> Now i need to get list of those directories which are missing in
> mirror1.

find /data | sort > find.mirror1

find /data | sort > find.mirror2

diff find.mirror1 find.mirror2

--
Bowie
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-23-2008, 02:16 PM
"William L. Maltby"
 
Default compare directories

On Thu, 2008-10-23 at 11:53 +0200, David Hláčik wrote:
> Hello guys,
>
> I have two mirrors. I need to compare files and directories on both
> mirrors and as a result print list of those which are missing on
> mirror 2
>
> What i did
>
> find /data > find.mirror1
>
> find /data > find.mirror2
>
> Now i need to get list of those directories which are missing in
> mirror1.

diff --brief --recursive /dir1 /dir2 &> /tmp/dir1vsdir2 # good enough?

$ mkdir dir1 dir2
$ mkdir dir1/{a,b,c,d} dir2/{b,d}
$ diff --recursive --brief dir1 dir2
Only in dir1: a
Only in dir1: c
$

>
> Thanks in advance!
>
> David
> <snip sig stuff>

HTH
--
Bill

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-23-2008, 05:15 PM
Bill Campbell
 
Default compare directories

On Thu, Oct 23, 2008, Bowie Bailey wrote:
>David Hlácik wrote:
>> Hello guys,
>>
>> I have two mirrors. I need to compare files and directories on both
>> mirrors and as a result print list of those which are missing on
>> mirror 2
>>
>> What i did
>>
>> find /data > find.mirror1
>>
>> find /data > find.mirror2
>>
>> Now i need to get list of those directories which are missing in
>> mirror1.
>
>find /data | sort > find.mirror1
>
>find /data | sort > find.mirror2
>
>diff find.mirror1 find.mirror2

A somewhat cleaner way of doing this is to use the ``comm'
command as it generates a straight list as opposed to diff which
requires parsing the output.

cd /dir1
find . | sort > /tmp/find.mirror1
cd /dir2
find . | sort > /tmp/find.mirror2

# This will give a list of lines in mirror2 not in mirror1
comm -13 /tmp/find.mirror1 /tmp/find.mirror2 > /tmp/missingfrom1

# This will give a list of files in mirror1 not in mirror2
comm -23 /tmp/find.mirror1 /tmp/find.mirror2 > /tmp/missingfrom2

Bill
--
INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186

Democracy must be sometihng more than two wolves and a sheep voting on what
to have for dinner -- James Bovard
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-23-2008, 06:06 PM
MHR
 
Default compare directories

On Thu, Oct 23, 2008 at 10:15 AM, Bill Campbell <centos@celestial.com> wrote:
>
> A somewhat cleaner way of doing this is to use the ``comm'
> command as it generates a straight list as opposed to diff which
> requires parsing the output.
>

But comm also "requires" that the data be sorted. Otherwise you can
get spurious output because lines that are actually the same but do
not appear in order will show up as differences.

I'd go with the rsync solutions already posted, but that's just me.

mhr
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-23-2008, 06:13 PM
Bill Campbell
 
Default compare directories

On Thu, Oct 23, 2008, MHR wrote:
>On Thu, Oct 23, 2008 at 10:15 AM, Bill Campbell <centos@celestial.com> wrote:
>>
>> A somewhat cleaner way of doing this is to use the ``comm'
>> command as it generates a straight list as opposed to diff which
>> requires parsing the output.
>>
>
>But comm also "requires" that the data be sorted. Otherwise you can
>get spurious output because lines that are actually the same but do
>not appear in order will show up as differences.

That's certainly true, which is why my solution, and the one with
diff both sorted the find output before the comparison.

I use the ``comm' solution quite frequently for this, and to do
things like compare ``rpm -ql packagename' with ``rpm -qpl' to
be sure that modifications I have made to a package have not
added or lost something compared to the installed version.

I find ``comm' to be a very useful program that people may not
know of, and I use it in Linux/Unix classes I teach to show
people how CLI programs may make things much easier than GUIs.

>I'd go with the rsync solutions already posted, but that's just me.

Bill
--
INTERNET: bill@celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186

One of the common failings among honorable people is a failure to
appreciate how thoroughly dishonorable some other people can be, and how
dangerous it is to trust them.
- Thomas Sowell
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 10-23-2008, 08:15 PM
MHR
 
Default compare directories

On Thu, Oct 23, 2008 at 11:13 AM, Bill Campbell <centos@celestial.com> wrote:
>
> That's certainly true, which is why my solution, and the one with
> diff both sorted the find output before the comparison.
>

Oh, I thought I was just seeing double again.

Oops! :-)

mhr
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 07:53 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org