How to Recursively Find All Files in Directories/Subfolders by Wildcards
Jun 04, 2025 am 09:57 AMUsers might encounter situations where they need to locate all files within a directory, folder, or subfolder hierarchy that contain a specific string but with variations in the file names. This scenario is ideal for using wildcard matches to find files.
For instance, perhaps you want to locate every file on the system that includes the word “invoice,” regardless of its position in the filename (such as invoice1-2023.pdf, big-invoice-wow.pdf, yourfavoriteinvoice.pdf, invoice-2-22.pdf, etc.).
This article will demonstrate how to use the command line to recursively search directories and subdirectories for files matching a string of text, utilizing several practical examples.
How to Recursively Search for All Files Using Wildcards
We’ll utilize the find
command, which, as its name suggests, enables you to locate files in the file system directly from the command line.
find . -name "text*"
This command breaks down as follows:
find [directory]
(Here, “.” represents the current directory) -name "[matched text and wildcards]"
(Here, filenames matching ‘text’ followed by any characters).
To find matches with wildcards both before and after the specified text, use the following command, replacing “text” with the appropriate syntax for your specific use case:
find . -name "*text*"
Using the example provided earlier, suppose you’re attempting to locate all files containing the text “invoice” in their filenames, regardless of their location within the user’s entire home directory structure. The syntax for such a search might look similar to the following:
find ~/ -name "*invoice*"
Running that command might produce output resembling the following:
/Users/Paul//Library/Application Support/CloudAppHoldingFiles/mystery-invoice-2023.pdf/Users/Paul//Library/Application Support/WhoKnows/invoice-2024.pdf/Users/Paul/Documents/big-invoice-wow.pdf/Users/Paul/Documents/Misc/small-invoice-dontforget.pdf/Users/Paul/Desktop/YouForgotAboutThisInvoice.pdf/Users/Paul/Desktop/AnotherInvoice.pdf/Users/Paul/Documents/Invoices/invoice-1-23.pdf/Users/Paul/Documents/Invoices/invoice-3-23.pdf/Users/Paul/Documents/Invoices/invoice-4-23.pdf/Users/Paul/Documents/Invoices/invoice-5-23.pdf/Users/Paul/Documents/Invoices/invoice-6-23.pdf
As evident, this command and file-finding process is especially useful when tracking down files dispersed throughout a file system based solely on name matches and wildcards.
Although you can also use Spotlight or Finder to attempt locating all matches, recent modifications to Spotlight seem to make finding all files more challenging. Additionally, while Finder searches can incorporate wildcards for name matches, the command line remains simpler for many users. If Finder proves easier, you might find this tip for listing all files in subdirectories recursively beneficial as well.
If you employ an alternative method for recursively searching directories via wildcard matches, please share your approach in the comments section below!
The above is the detailed content of How to Recursively Find All Files in Directories/Subfolders by Wildcards. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you're using a Mac with multiple monitors, you might be curious about how to display the Dock on all screens or whether it's possible to add a Dock to secondary displays.The good news is that you can configure the Dock to appear on any screen conn

Fortnite is once again available for iPhone and iPad users, bringing joy to many gamers. However, there's still no official version for Mac (at least not yet). Despite that, Apple Silicon Mac owners aren’t completely out of luck—you can run the iOS/i

If you've owned multiple Apple devices over the years, you might find yourself in a situation where some of those older Macs, iPhones, iPads, or other Apple hardware have been sold, given away, or traded. No matter how they left your possession, it's

iCloud Private Relay is an excellent privacy feature included with the iCloud subscription, designed to safeguard your online activity and browsing by masking your IP address (using a temporary one) and encrypting DNS lookups. This prevents third pa

Are you using Screen Time to manage your or your child’s Mac usage? If yes, you likely already know that it allows you to set app limits, schedule downtime on the Mac, and more. Additionally, you can also choose specific apps that remain accessible a

macOS Sequoia is a solid operating system that brings some impressive features like iPhone Mirroring, and while performance is excellent for many users, not everyone experiences the same level of speed. If you're finding macOS Sequoia slower than pre

If you frequently use iMessage, then you've likely shared numerous web links in your chats — maybe an article, a video, a tweet, a song, or anything else. Locating these links later can be quite frustrating, but thankfully there's a simpler method th

Advanced Mac users familiar with the command line can swiftly set up a MacOS Tahoe 26 beta virtual machine by entering a few commands into Terminal, using tart. Tart is a command-line utility for managing virtual machines and offers one of the quicke
