|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
A question from a beginner
Hi, I am new to Unix OS, so my question may be so easy for you but please be enough kind to help
![]() I need to find duplicate files in two directories ,and copy them to an other directory. smt like; finddublicate.sh dir1 dir2 and this scrict should find and copy duplicate files in this dir1 and dir2 and copy them in to a default directory (say dir3). Any suggestions? |
|
#2
|
|||
|
|||
|
Quote:
not really easy. what do you mean: duplicate filename or duplicate filecontent ? |
|
#3
|
|||
|
|||
|
Quote:
two files with same name and same file content |
|
#4
|
|||
|
|||
|
i really don't understand your probl
assumed this is true: two files with same name and same file content try something like: Code:
#!/bin/sh
mkdir -p ${d3:=third-directory} ¦¦ exit 1
cmpme()
{
for one in `ls $1`
do for two in `ls $2`
do case $one in $two) ;; *) continue;; esac
cmp $1/$one $2/$two ¦¦ continue
# one and two have the same NAME and CONTENT
[ -f $d3/$one -o -d $d3/$one ] && continue # $one still present in $d3, Q should one and two be removed ?
mv $1/$one $d3
rm -rf $2/$two
done
done
}
# main program
cmpme dirone dirtwo
cmpme dirtwo dirone
exit 0
NOT TESTED, just an idea there is sure a better way, explain the probl. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > A question from a beginner |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|