小能豆

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

Linux

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


阅读 93

收藏
2023-12-25

共1个答案

小能豆

You can use the find command in the terminal to recursively find files based on wildcard matching. Here’s an example that finds all files in the current and subfolders with a .txt extension

find . -type f -name "*.txt"

Let’s break down the command:

  • .: Specifies the starting directory (in this case, the current directory).
  • -type f: Limits the search to files only (not directories).
  • -name "*.txt": Matches files with names ending in .txt. The * is a wildcard that matches any characters.

You can adapt this command based on your specific wildcard matching requirements. For example:

  • To find all Python files: find . -type f -name "*.py"
  • To find all files starting with “report”: find . -type f -name "report*"
  • To find all files with a specific pattern in the name: find . -type f -name "*pattern*"

Adjust the *.txt part according to the pattern or wildcard matching you need.

If you want to include hidden files (those starting with a dot), you can use the -name option without the leading dot:

find . -type f -name "*pattern*"

Remember that the syntax might vary slightly depending on your shell and operating system. The examples provided should work in most Unix-like environments, including Linux and macOS.

2023-12-25