LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-14-2006, 09:47 PM   #1
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
deleting duplicate files


Hey,

Does anyone know of an app or maybe a shell trick that would let me remove duplicates in a directory? I moved my mail server to another computer and due to a stupid typo on my part I now have 2 of every email in 6 mailboxes which is leading to some curious phone calls from people

It's not a life threatening situation but if anyone has any suggestions I'd love to hear them

TIA
 
Old 11-14-2006, 10:41 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Not sure of the precise details of your situation. Are these files with same name in different dirs or files with different names but the same contents? Etc. Anyway - simplest thing for some situations might be http://www.homepages.lu/pu/fdups.html
 
Old 11-14-2006, 11:18 PM   #3
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
This is a script I have been working on that seems to work with image files. It's not a perfect script and pobably not the best way written, but you maybe able to mess around with it a bit to work with email messages. I have made it by default move files to a duplicate directory rather than deleting them, just so you can check before finally deleting them

########################################################
#!/bin/sh

OUTPUT=duplicates
DUPES=rem.sh

# remove any previous files
rm -rf $OUTPUT
rm -rf $DUPES

find . "$@" -type f -print0 |
xargs -0 -n1 md5sum |
sort --key=1,32 | uniq -w 32 -d --all-repeated=separate | \
sed -e '$!N; /^\(.*\)\n\1$/!P; D' >> $OUTPUT

cat > $DUPES<<'EOF'
#!/bin/sh
ME=`whoami`
DUPE_DIR=~/$ME/duplicates
if [ ! -d $DUPE_DIR ]; then
mkdir -p $DUPE_DIR
fi
FOUND='
EOF

cat $OUTPUT | sed -n '/^$/{p;h;};/./{x;/./p;}' >> $DUPES
cat >> $DUPES <<'EOF'
'
for x in $FOUND; do
mv $x $DUPE_DIR
done
EOF

sh rem.sh
########################################################

Just test this first in a test directory before actually using it, not sure how good it will work for you.
 
Old 11-14-2006, 11:27 PM   #4
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
sorry double post
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash - Deleting duplicate records Wire323 Programming 5 12-04-2005 08:51 AM
editors and duplicate files printf Linux - Newbie 7 11-22-2005 03:54 AM
Deleting duplicate messages essdeeay Linux - General 1 11-20-2005 07:58 AM
duplicate files in one folder! hornung Linux - Enterprise 1 01-13-2005 03:35 PM
Duplicate Files and linux carl0ski Linux - Software 1 12-22-2004 04:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration