50

I am using Ubuntu and I want to search for a specific Directory called "sdk".

All that I know is, that "sdk" Directory is located somewhere under /user Directory

how can I search for "sdk" Directory from the terminal?

I tried the following find / -name example docs -type d

but it says no such file or Directory.

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 3
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Dec 19 '17 at 13:08

2 Answers2

91

you can search for directory by using find with flag -name

you should use

find /user -name "sdk" -type d

meaning find directories named sdk in or below the directory /user

or if you want to be case-insensitive

find /user -iname "sdk" -type d
Julio Spinelli
  • 587
  • 3
  • 16
recycler
  • 1,301
  • 9
  • 9
  • 8
    For perf reasons put the `-type d` before the name check as it's cheaper to check if a node is a directory. The order matters with `find` – mike3996 Mar 25 '19 at 10:58
12

Please try the below command.

locate foldername | grep /foldername$
Codebrekers
  • 754
  • 1
  • 11
  • 29
Swapan Shaw
  • 173
  • 1
  • 10
  • 5
    `locate -r` accepts a regex so no need to grep. Besides, linux/unix has directories, not folders – mike3996 Mar 25 '19 at 10:59
  • This solution worked a lot better for me than the one with all the votes because the other solution seemed to return every directory. Using just ```locate directory``` like the other comment says has the problem of returning all sub directories that have it in the path. – zawy Feb 13 '22 at 12:08