LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 07-24-2010, 12:14 AM   #1
xzased
LQ Newbie
 
Registered: Jan 2008
Posts: 20

Rep: Reputation: 0
Find duplicate files by name


Hi, we have a huge amount of duplicate files in a folder and I would like some pointers on to writing a bash script to create a list of the duplicate files. I've seen examples that check for the md5 sum of files... but I dont need that, the file name is enough. Can someone please help me?
 
Old 07-24-2010, 12:29 AM   #2
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 146Reputation: 146
Quote:
Originally Posted by xzased View Post
Hi, we have a huge amount of duplicate files in a folder and I would like some pointers on to writing a bash script to create a list of the duplicate files ... the file name is enough.
Umm, it should not be possible to have two files with the same name in the same folder.
 
Old 07-24-2010, 12:59 AM   #3
xzased
LQ Newbie
 
Registered: Jan 2008
Posts: 20

Original Poster
Rep: Reputation: 0
LOL! True Mr. Telengard. I meant in subfolders. So I have the directory /storage which holds about 10 subfolders which hold around 3 more subfolders each with around 300 + files in. Messy, I know. So the duplicates are between subfolders.
 
Old 07-24-2010, 01:06 AM   #4
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 146Reputation: 146
Okay, this has had only very minimal testing so use at your own discretion. As always, it is your responsibility to evaluate this code's suitability for your purposes.

Code:
#!/bin/bash

find -type f > names.lst

while read name
do
    bn="$( basename "$name" )"
    name2="$( grep "$bn" names.lst | grep -v "$name" )"
    if [ "$name2" != "" ]
    then
	echo "$name"
	echo "$name2"
    fi
done < names.lst
I bet 3 Internets that someone else will have a much more elegant solution for you by tomorrow.
 
1 members found this post helpful.
Old 07-24-2010, 01:35 AM   #5
xzased
LQ Newbie
 
Registered: Jan 2008
Posts: 20

Original Poster
Rep: Reputation: 0
Wow, thanks sir. Your help is appreciated.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Software to find duplicate files mike_savoie Linux - Software 5 07-17-2010 03:04 PM
Best tool to find duplicate files? arfon Linux - Software 1 05-16-2010 11:51 AM
Script to find the duplicate files Tekken Linux - Server 5 09-18-2009 12:46 AM
Find Duplicate Files caponewgp Linux - Newbie 9 09-10-2009 12:20 AM
Howto find duplicate files js72 Linux - Software 1 11-09-2003 04:55 AM


All times are GMT -5. The time now is 07:25 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration