67

How can I find a particular directory in a terminal window in Linux? I think it involves using grep, but I'm not sure how.

3
  • removing find-in-files tag since you are locating a directory, no file-content-search is implied.
    – nik
    Commented Jul 2, 2010 at 5:44
  • What do you know about the directory that would allow you to find it?
    – David Z
    Commented Jul 2, 2010 at 5:58
  • 1
    you have to provide at least some search criteria, "particular" is a bit vague. one can find items on the disc based upon names, relation ships, sizes, content, etc etc.
    – akira
    Commented Jul 2, 2010 at 7:16

3 Answers 3

92

Would you be looking for something like this?

find . -type d | grep DIRNAME
4
  • 28
    what's wrong with find . -name DIRNAME -type d? Commented Jul 2, 2010 at 5:47
  • 5
    @honk, Nothing :-) -- the OP seems to like grep; and we all like variety
    – nik
    Commented Jul 2, 2010 at 5:51
  • whats the difference?
    – Dobler
    Commented May 22, 2015 at 5:13
  • Five years later I did notice the answer in the comment was slower to process than the original answer. Maybe a glitch. Anyone? Bueller?
    – aCodeSmith
    Commented Jun 17, 2015 at 3:45
34

If you want to find a particular directory that might be anywhere on your computer, the following will work, but it might take a while.

find / -name DIRNAME -type d
1
  • 6
    And, if you want to find within the working directory -- replace '/' with '.' -- could get quicker.
    – nik
    Commented Jul 2, 2010 at 5:52
4

If you have it installed, locate is designed for this. Google "man locate"

3
  • Though locate won't provide you real-time results, but instead returns the results it gathered while updatedb was last run. If the filesystem doesn't change much, then it isn't a real problem and locate is very fast. Commented Jul 29, 2010 at 11:12
  • -1 Locate is designed to find files, not directories. Or is there an option I am not aware of?
    – Martin R.
    Commented Jul 13, 2017 at 16:26
  • locate works just fine for directories.
    – TREE
    Commented Jul 13, 2017 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .