LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-06-2011, 06:10 PM   #1
wonfineday
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Rep: Reputation: Disabled
How to list duplicate filenames


How can I see a list of duplicate file names (even if content is different) under a given directory?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-06-2011, 06:26 PM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Hi and welcome to LQ.

I don't think you can have duplicate file names (ie. identical file names) in the same directory. You can have files with different extensions (eg. file.jpg, file.png, etc.) but I wouldn't call them duplicate.
 
1 members found this post helpful.
Old 12-06-2011, 06:33 PM   #3
wonfineday
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
List duplicate filenames under a subdirectory

Perhaps I should clarify:
- I want to see a list of all files named foo.txt under ~/
- thus files name ~/dir1/foo.txt, ~/dir1/subdir1/foo.txt, ~/dir2/foo.txt should all be listed out (so I can then manually verify that they are indeed different)
 
Old 12-06-2011, 08:05 PM   #4
aazkan
Member
 
Registered: Jan 2008
Posts: 72

Rep: Reputation: 5
Hi,

Would this help?
In the directory where foo.txt files, do

Code:
find . -type f -name "foo.txt" -print

Last edited by aazkan; 12-06-2011 at 08:07 PM. Reason: Typo error, foo.txt instea of foot.txt
 
Old 12-06-2011, 09:28 PM   #5
wonfineday
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
How to find duplicate filenames under a subdirectory

Thanks for the suggestion aazkan, it might help if I was looking for a specific file. I need to identify ALL duplicate filenames.
 
Old 12-07-2011, 12:56 AM   #6
coolsg5636
Member
 
Registered: Sep 2011
Location: Pune,India
Distribution: RHEL ,CentOS, Fedora
Posts: 100

Rep: Reputation: 25
I guess you will need to write a script for it and that script will not be resource efficient as it has to compare the file names of each file with all other files in the the mentioned directory.

Do you have any knowledge of scripting ?

Is this a exam/classroom question ?
 
Old 12-07-2011, 01:36 AM   #7
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

LQ has a great search option, which turned up this one right here at LinuxQuestions. It should be a good base for what you need.

Here are some more possible solutions, found using Google in under a second.

Kind regards,

Eric

Last edited by EricTRA; 12-07-2011 at 01:37 AM.
 
Old 12-07-2011, 01:51 AM   #8
devUnix
Member
 
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 576

Rep: Reputation: 48
Code:
[demo@localhost temp]$ find `pwd` . | grep -v '^\.' | awk -F '/' '{print $NF,$0}' | sort +0 -1
bye /home/demo/temp/bye
bye /home/demo/temp/there/bye
duplicate.sh /home/demo/temp/duplicate.sh
hello_again /home/demo/temp/there/hello_again
hello /home/demo/temp/hello
hello /home/demo/temp/there/hello
temp /home/demo/temp
there /home/demo/temp/there
Or

Code:
[demo@localhost temp]$ find `pwd` . | grep -v '^\.' | awk -F '/' '{print $NF,$0}' | sort +0 -1 | cut -d ' ' -f2
/home/demo/temp/bye
/home/demo/temp/there/bye
/home/demo/temp/duplicate.sh
/home/demo/temp/there/hello_again
/home/demo/temp/hello
/home/demo/temp/there/hello
/home/demo/temp
/home/demo/temp/there
[demo@localhost temp]$

Or:

For the Ease of Visualisation!

Code:
[demo@localhost temp]$ find `pwd` . | grep -v '^\.' | awk -F '/' '{print $NF " ->",$0}' | sort +0 -1
bye -> /home/demo/temp/bye
bye -> /home/demo/temp/there/bye
duplicate.sh -> /home/demo/temp/duplicate.sh
hello -> /home/demo/temp/hello
hello -> /home/demo/temp/there/hello
hello_again -> /home/demo/temp/there/hello_again
temp -> /home/demo/temp
there -> /home/demo/temp/there
Cheers!


Or put this in a file:


Code:
# Find Duplicate File Names - By Dev (dk_mahadeva@yahoo.com)
#
#!/bin/bash
path=$1
: ${path:=.}
fullList=$(find `pwd` $path | grep -v '^\.' | awk -F '/' '{print $NF,$0}' | sort +0 -1)
fileNames=$(find `pwd` $path | grep -v '^\.' | awk -F '/' '{print $NF}' | sort | uniq -d)
for EACH in $fileNames; do
	echo "$fullList" | grep -wE "^$EACH "
done
exit 0
Example:

Code:
[demo@localhost temp]$ ./findDup.sh /home 2> /dev/null | head -n 4
bye /home/demo/bye
bye /home/demo/temp/bye
bye /home/demo/temp/bye
bye /home/demo/temp/there/bye
If no command-line argument/parameter (path to being from) is specified then the default is to begin from the current (.) directory.

Feeling glad now?

Last edited by devUnix; 12-07-2011 at 02:19 AM.
 
3 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
list filenames with spaces in a shell script xp_newbie Programming 6 03-15-2009 08:46 PM
script to list the filenames which are in lower case naveensankineni Programming 2 03-12-2008 08:09 AM
Need a Download Mgr that renames duplicate filenames RyMcV Linux - Software 1 07-01-2007 04:51 PM
Duplicate filenames in kernel source bz2 archive amn Linux - Newbie 4 03-20-2007 05:49 AM
Folder List With Numbers Over 100 In Filenames hazmatt20 Linux - General 14 01-09-2006 03:17 AM


All times are GMT -5. The time now is 02:19 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration