-   Linux - Newbie (
-   -   Find Directory only (

doby48 07-19-2010 04:48 PM

Find Directory only
From terminal I am looking for a way to use the find or grep command to find all occurrences of a specific directory name. I would like to strip out all files thus removing duplicate folder listings. So for example, if I wanted to see all the lib dirs on my computer, I couldn't just do:

find / lib

As this not only shows all lib dirs but also would list directories multiple times due to certain ones have multiple files in the path. So I would want to just know that there is a dir called /var/lib and would not want the output to include


And so on. Thanks for any assistance.

anomie 07-19-2010 04:56 PM

See the manpages for find(1) -- specifically, the type option.

Telengard 07-19-2010 04:57 PM

Try find /path/to/search -type d -name 'DIRECTORY_NAME'. For example:


$ find /usr/ -type d -name 'doc'

If you are uncertain about the upper case letters in the directory name then use the -iname argument instead of -name.

Lastly, be sure to try this:


$ man find

colucix 07-19-2010 04:58 PM

Adding -type d to the search criteria should do the trick. E.g.

find / -type d -name lib\*
Please, see man find or the GNU find manual for details.

doby48 07-19-2010 05:14 PM

Thanks, I actually had looked at the man pages but must have missed the -type option.

All times are GMT -5. The time now is 01:55 AM.