linux - How can I recursively find all files in current and subfolders based on wildcard matching?

ID : 304

viewed : 156

Tags : linuxshelllinux

Top 5 Answer for linux - How can I recursively find all files in current and subfolders based on wildcard matching?

vote vote

95

Use find for that:

find . -name "foo*" 

find needs a starting point, and the . (dot) points to the current directory.

vote vote

82

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 
vote vote

70

find will find all files that match a pattern:

find . -name "*foo" 

However, if you want a picture:

tree -P "*foo" 

Hope this helps!

vote vote

63

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

vote vote

59

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

Top 3 video Explaining linux - How can I recursively find all files in current and subfolders based on wildcard matching?

Related QUESTION?