LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-13-2012, 04:03 AM   #1
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Rep: Reputation: 0
Identify double occurrence of directory names


Dear All,
I am looking for a shell command that will identify all directories, each of which having the same name as one of its subdirectory.
For example:
Code:
/as/df/gh/sq12/sq12
or
Code:
/fgd/hgtre/gtsrew/hgt/mydirectory/mydirectory
Thanks
 
Old 09-13-2012, 04:29 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
find <root> -type d | grep -E '(/[^/]+)(/.+)?\1(\/|$)'
works for me, but probably not perfect
 
Old 09-13-2012, 05:32 AM   #3
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks,
and how can I filter from these results directories with certain patterns such as
dir1/dir2/dir3/mydir/mydir/ (the name starts with 'myd'
Thanks again
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Listing file names side by side with directory names anon84 Linux - Newbie 3 04-03-2012 10:13 AM
[SOLVED] List files/directory names without directory contents? littlebigman Linux - Software 2 05-03-2011 04:42 AM
[SOLVED] How to changing same file names by their directory names? bayaraa_u Linux - General 3 04-09-2010 08:26 AM
What do the directory names stand for jken Linux - General 4 08-26-2004 07:26 AM
directory-names with spaces... Schmurff Linux - Newbie 2 03-07-2004 11:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:59 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