LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find Directory only (http://www.linuxquestions.org/questions/linux-newbie-8/find-directory-only-820791/)

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

/var/lib/gdm
/var/lib/gdm/.cache
/var/lib/rpm

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:

Code:

$ find /usr/ -type d -name 'doc'
/usr/share/vim/vim71/doc
/usr/share/qt3/doc
/usr/share/apps/pykdeextensions/app_templates/kdeapp/doc
/usr/share/apps/pykdeextensions/app_templates/kioslave/doc
/usr/share/apps/pykdeextensions/app_templates/kcontrol_module/doc
/usr/share/apps/pykdeextensions/app_templates/kdeutility/doc
/usr/share/doc
/usr/local/share/doc
/usr/lib/python2.5/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:

Code:

$ man find

colucix 07-19-2010 04:58 PM

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

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 09:47 AM.