How can I search a wild card name in all subfolders?
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*'
Zsh:
ls -ld -- **/*abcd*
Ksh93:
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*
Yash:
set -o extendedglob # put this line in your ~/.yashrc
ls -ld -- **/*abcd*
tcsh:
set globstar
ls -ld -- **/*abcd*
fish:
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.