Operating System - HP-UX
1833589 Members
4061 Online
110061 Solutions
New Discussion

Re: dir comparison script help

 
nauman sheikh
New Member

dir comparison script help

I have two directories; dirA and dirB. Each contains very large number of ordinary files.
I wanted to find out the duplicate file name in each dir. If found, write the duplicate file name with full attributes to log and send out a notification to particular user/owner to remove the file from the dir.

example:
dirA
file1
file2
file3

dirB
file1
file4
file5

Can someone help me on this.

Thanks in advance

3 REPLIES 3
Patrick Wallek
Honored Contributor

Re: dir comparison script help

Have a look at the dircmp command.

# man dircmp

for more information.
Stephen Keane
Honored Contributor

Re: dir comparison script help

Or

# find dirA -type f -print | sort > filelistA
# find dirB -type f -print | sort > filelistB
# comm -3 filelistA filelistB > commonfiles
# find `cat commonfiles` -exec your_script {} \;

Chris Vail
Honored Contributor

Re: dir comparison script help

In Unix, there are any number of ways to do just about anything. Here's how I would approach your problem:

cd /dir1
for i in `ls -1`
do
if test -f dir2/$i
then
echo "$i is a duplicate"
ls -l dir2/$i >>/logfile
OWNER=`ls -l dir2/$i|awk '{print $3}`
STRING="$i is a duplicate file"
echo "$STRING"|mailx -s "$i is a duplicate" $OWNER@somewhere.com
fi
done