LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 07-19-2010, 03:48 PM   #1
doby48
LQ Newbie
 
Registered: Sep 2008
Location: Minnesota (USA)
Distribution: Slackware, Fedora
Posts: 22

Rep: Reputation: 15
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.
 
Old 07-19-2010, 03:56 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
See the manpages for find(1) -- specifically, the type option.
 
Old 07-19-2010, 03:57 PM   #3
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
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
 
Old 07-19-2010, 03:58 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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.
 
Old 07-19-2010, 04:14 PM   #5
doby48
LQ Newbie
 
Registered: Sep 2008
Location: Minnesota (USA)
Distribution: Slackware, Fedora
Posts: 22

Original Poster
Rep: Reputation: 15
Thanks, I actually had looked at the man pages but must have missed the -type option.
 
  


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
find exactly in that directory basak Linux - Newbie 1 08-21-2006 08:26 AM
How to find a string in a directory? iclinux Linux - Newbie 2 07-02-2005 08:20 AM
How can i find the difference for directory alice95089 Linux - Software 4 02-07-2005 08:49 AM
exclude directory from find ebasi Linux - Software 8 07-17-2004 02:12 AM
Can't find CD images directory rrose42 Linux - Software 3 02-04-2002 06:01 AM


All times are GMT -5. The time now is 03:29 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration