It appears you have not registered with our community. To register please click here ...

Author Topic: Searching multiple duplicate files  (Read 1461 times)

thedarkdestroyer100

  • Newbie
  • *
  • Posts: 1
  • Karma: +10/-0
    • View Profile
    • Email
Searching multiple duplicate files
« on: March 20, 2006, 05:13:30 PM »
hi, i am trying to get a working script that searches a filesystem from a start point (set using the -s option) and find all duplicate files with a certain criteria. The output has to use the -f option to display the output. I have tried this script but cant get it working so far. Any help greatly appreciated.
Thanks

OUTF=rem-duplicates.sh;
echo "#! /bin/sh" > $OUTF;
find "$@" -type f -print0 |
  xargs -0 -n1 md5sum |
    sort --key=1,32 | uniq -w 32 -d --all-repeated=separate |
    sed -r \'s/^[0-9a-f]*( )*//;s/([^a-zA-Z0-9./_-])/\\\\\\1/g;s/(.+)/#rm \\1/\' >> $OUTF;
chmod a+x $OUTF; ls -l $OUTF

dynaweb

  • <b>Canine Deamon</b>
  • Administrator
  • Sr. Member
  • *****
  • Posts: 493
  • Karma: +10/-0
  • Generic personal text here ...
    • MSN Messenger - danno_d_manno@yahoo.com
    • View Profile
    • DynaWeb Designs
    • Email
Searching multiple duplicate files
« Reply #1 on: March 21, 2006, 10:38:44 AM »
Quote
from a start point (set using the -s option)


I don\'t see the -s in your script.
Those who cannot learn from history are doomed to repeat it. -- Linux learns.

dynaweb

  • <b>Canine Deamon</b>
  • Administrator
  • Sr. Member
  • *****
  • Posts: 493
  • Karma: +10/-0
  • Generic personal text here ...
    • MSN Messenger - danno_d_manno@yahoo.com
    • View Profile
    • DynaWeb Designs
    • Email
Find and remove duplicate files - shell script
« Reply #2 on: March 21, 2006, 11:39:08 AM »
Try this script instead:

Code: [Select]
# findd.sh from http://www.linuxboards.org
# Finds all duplicate files using md5chksum and prints them out on the screen
# Change /root/danno/ to a directory where you wish to search recursively
# If satisfied with initial output then remove the # comment tag from
# before the rm command and run again to delete the duplicates
#!/bin/sh

fr=0
cksum $(find /root/danno/ -type f -print)|sort -k 1,1n |
while read c1 c2 n3
do
   # save check sums and file names
   if [[ $fr -eq 0 ]]
   then
      fr=1
      prevchksum=$c1
      prevfile=$n3
      continue
   fi
   # if current checksum equals saved checksum,
   # the file is a duplicate
   if [[ $prevchksum -eq $c1 ]]
   then
      echo "file $prevfile has duplicate $n3"; #rm $n3
   else
      prevchksum=$c1
      prevfile=$n3
   fi
done
# end script


Let me know if that works for you.
Those who cannot learn from history are doomed to repeat it. -- Linux learns.

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
378 Views
Last post November 13, 2005, 03:30:16 AM
by Linux News
0 Replies
233 Views
Last post December 03, 2005, 08:51:57 AM
by Linux News
1 Replies
2329 Views
Last post January 26, 2006, 10:03:58 AM
by dynaweb
2 Replies
2059 Views
Last post May 15, 2006, 04:17:08 PM
by ctwjr
2 Replies
1980 Views
Last post March 15, 2010, 01:37:15 AM
by Njordewind