linux - [Solved-7 Solutions] How to recursively find all files in current and subfolders based on wildcard matching ? - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

How to recursively find all files in current and subfolders based on wildcard matching ?

Linux - Solution 1:

Use find for that:

find . -name "wikitechy*"
click below button to copy the code. By - Linux tutorial - team

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

Linux - Solution 2:

To find all files with case insensitive string "wikitechy" in the filename:

~$ find . -print | grep -i wikitechy
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 3:

find will find all files that match a pattern:

find . -name "*wikitechy"
click below button to copy the code. By - Linux tutorial - team

However, if you want a picture:

tree -P "*wikitechy"
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 5:

find -L . -name "wikitechy*"
click below button to copy the code. By - Linux tutorial - team
  • In a few cases, -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

Linux - Solution 6:

If you shell supports extended globbing (enable it by: shopt -s globstar), you can use:

echo **/*wikitechy*
click below button to copy the code. By - Linux tutorial - team

To find any files or folders recursively. This is supported by Bash, zsh and similar shells.

Linux - Solution 7:

find <directory_path>  -type f -name "<wildcard-match>"
click below button to copy the code. By - Linux tutorial - team

In the wildcard-match you can provide the string you wish to match e.g. *.c (for all c files)


Related Searches to - linux - linux tutorial - How to recursively find all files in current and subfolders based on wildcard matching ?