How can I recursively find all files in current and subfolders based on wildcard matching?
How can I recursively find all files in current and subfolders based on wildcard matching?
Question
How can I recursively find all files in current and subfolders based on wildcard matching?
Read more… Read less…
Piping find into grep is often more convenient; it gives you the full power of regular expressions for arbitrary wildcard matching.
For example, to find all files with case insensitive string "foo" in the filename:
~$ find . -print | grep -i foo
find
will find all files that match a pattern:
find . -name "*foo"
However, if you want a picture:
tree -P "*foo"
Hope this helps!
find -L . -name "foo*"
In a few cases, I have needed the -L parameter to handle symbolic directory links. By default symbolic links are ignored. In those cases it was quite confusing as I would change directory to a sub-directory and see the file matching the pattern but find would not return the filename. Using -L solves that issue. The symbolic link options for find are -P -L -H
fd
In case, find
is too slow, try fd
utility - a simple and fast alternative to find
written in Rust.
Syntax:
fd PATTERN
Demo:
Homepage: https://github.com/sharkdp/fd
If your shell supports a new globbing option (can be enabled by: shopt -s globstar
), you can use:
echo **/*foo*
to find any files or folders recursively. This is supported by Bash 4, zsh and similar shells.
Personally I've got this shell function defined:
f() { find . -name "*$1*"; }
Note: Above line can be pasted directly to shell or added into your user's ~/.bashrc
file.
Then I can look for any files by typing:
f some_name
Alternatively you can use a fd
utility with a simple syntax, e.g. fd pattern
.