dylanized dylanized - 2 years ago 109
Bash Question

Use bash to find first folder name that contains a string

I would like to do this in Bash:

  • in the current directory, find the first folder that contains "foo" in the name

I've been playing around with the find command, but a little confused. Any suggestions?

Answer Source

You can use the -quit option of find:

find <dir> -maxdepth 1 -type d -name '*foo*' -print -quit
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download