How can I search a wild card name in all subfolders? What would be the equivalent of DOS command: dir *pattern* /s in *nix?


You can use find. If, for example, you wanted to find all files and directories that had abcd in the filename, you could run:

find . -name '*abcd*'


ls -ld -- **/*abcd*


set -o globstar     # put this line in your ~/.kshrc
ls -ld -- **/*abcd*

Bash ≥4:

shopt -s globstar   # put this line in your ~/.bashrc
ls -ld -- **/*abcd*


set -o extendedglob # put this line in your ~/.yashrc
ls -ld -- **/*abcd*


set globstar
ls -ld -- **/*abcd*


ls -ld -- **abcd*

(beware some of those shells will follow symlinks when descending the directory tree; some of those that don't like zsh, yash or tcsh have ***/*abcd* to do it).

Portable (except to very old systems; OpenBSD took a long time but finally supports exec … + since 5.1):

find . -name '*abcd*' -exec ls -ld {} +

Not POSIX but works on *BSD, Linux, Cygwin, BusyBox:

find . -name '*abcd*' -print0 | xargs -0 ls -ld

Note that except in some BSDs, if no matching file is found, ls -ld will be run without arguments, so will list .. With some xargs implementations, you can use the -r option to work around that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.