UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old January 14th, 2005, 03:39 AM
sturmbright sturmbright is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 3 sturmbright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old January 16th, 2005, 06:07 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
Quote:
Originally Posted by sturmbright
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?



not really easy.
what do you mean: duplicate filename
or duplicate filecontent
?

Reply With Quote
  #3  
Old January 17th, 2005, 03:58 AM
sturmbright sturmbright is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 3 sturmbright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by guggach
not really easy.
what do you mean: duplicate filename
or duplicate filecontent
?

two files with same name and same file content

Reply With Quote
  #4  
Old January 18th, 2005, 07:30 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 33 m 4 sec
Reputation Power: 9
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > A question from a beginner


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway