1833871 Members
1732 Online
110063 Solutions
New Discussion

Files compare

 
GerGon
Regular Advisor

Files compare

To: Gurus
Subject: Please giveme a trick
I need to compare the files in two diferent directories on remote machines?
Which commands do that?
Before I use ls and find -not etc, but in HPux not work yet.

I need compare the files in the two directories and print the files that aren't in the second directory?
i.e.
Machine 1 Machine 2
DirectoryA DirectoryB
File1 File1
File2 File2
File3

I want to print la diference, like File3, because it isn't on machine 2..
9 REPLIES 9
Patrick Wallek
Honored Contributor

Re: Files compare

The easiest thing I can think of is to do an

# ls -1 | sort > machine1.file
on machine 1

# ls -1 | sort > machine2.file
on machine 2

Now copy the files to a directory on either machine 1 or machine 2 and then do

# diff machine1.file machine2.file

and see what your results are.
Paul Sperry
Honored Contributor

Re: Files compare

#diff file1 file2
James R. Ferguson
Acclaimed Contributor

Re: Files compare

Hi:

'diff' will compare directories or files. Do:

# diff dir1 dir2

See the man pages for more information.

Regards!

...JRF...
GerGon
Regular Advisor

Re: Files compare

Exist any way, to do the diff with remsh on one line, ie:
remsh hosts2 -n ls -d /dir2 | diff /Dir1 -

Some like this?
Sridhar Bhaskarla
Honored Contributor

Re: Files compare

Hi,

I assume that you have remsh access to both the systems. If so, use this small script.

if [ $# -ne 2 ]
then
echo Usage $0: host1:dir1 host2:dir2
exit
fi

HOST1=$(echo $1|awk '{FS=":";print $1}')
DIR1=$(echo $1|awk '{FS=":";print $2}')
HOST2=$(echo $2|awk '{FS=":";print $1}')
DIR2=$(echo $2|awk '{FS=":";print $2}')

echo $HOST1 $HOST2 $DIR1 $DIR2

remsh $HOST1 -n "find $DIR1" |sort >> list1$$
remsh $HOST2 -n "find $DIR2" |sort >> list2$$
clear
echo Files on $HOST1 but not on $HOST2 > log

comm -23 list1$$ list2$$ >> log

rm list*

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: Files compare

Hi (Again),

BTW, above orthodox script produces the result in an output file called log in the current directory.
It prints everything including the subdirectories and the files in them. If you don't want it, change the "find" command inside remsh to "ls -ald" or whatever you want.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Christian Tremblay
Trusted Contributor

Re: Files compare

dircmp does that, for more info: man dircmp
GerGon
Regular Advisor

Re: Files compare

Oky, Thanks to all..
KCS_1
Respected Contributor

Re: Files compare

# dircmp -s Dir1 Dir2(directory compare)
# diff file1 file2(file compare)

that's ok!!
Easy going at all.