Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When using grep you can search for a specific regex, but only inside of a file. Is there any way, I can search for a folder name?

share|improve this question

migrated from stackoverflow.com Apr 6 '11 at 0:29

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers

If you really mean regexp instead of shellglob, you may want to use

find <path> -regex '<regex>' -type d

eg.

find Code/ -E -regex '(bin|redblack)_tree\.hs' -type d

the option -E turns on extendend regexp, see man find for more.

share|improve this answer
add comment

I usually use find:

$ find . -name 'FolderBasename*' -type d

or for more complex queries

$ find . -regex '{FolderRegex}' -type d

As pointed out in the comments if you want case insensitive searches do -iname and -iregex

share|improve this answer
3  
-name doesn't take a regular expression. If you need to match with a regular expression, you probably want -regex or -iregex –  Mark Longair Apr 5 '11 at 19:32
    
@Mark You're right - my bad there. I usually only need the supported * and ? (see man find) to get things found. –  qor72 Apr 5 '11 at 19:37
add comment

If you are just concerned with matching the name you can simply use '-name' in find.

find <path> -name '<regex>' -type d
share|improve this answer
add comment

find is far better but a clunky answer to your question:

ls -l | grep '^d'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.