LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Identify double occurrence of directory names (https://www.linuxquestions.org/questions/linux-newbie-8/identify-double-occurrence-of-directory-names-4175427018/)

krojther 09-13-2012 04:03 AM

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

pan64 09-13-2012 04:29 AM

find <root> -type d | grep -E '(/[^/]+)(/.+)?\1(\/|$)'
works for me, but probably not perfect

krojther 09-13-2012 05:32 AM

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


All times are GMT -5. The time now is 04:19 AM.