Users 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!
以上がワイルドカードによるディレクトリ/サブフォルダーですべてのファイルを再帰的に見つける方法の詳細(xì)內(nèi)容です。詳細(xì)については、PHP 中國語 Web サイトの他の関連記事を參照してください。

ホットAIツール

Undress AI Tool
脫衣畫像を無料で

Undresser.AI Undress
リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover
寫真から衣服を削除するオンライン AI ツール。

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡(jiǎn)単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中國語版
中國語版、とても使いやすい

ゼンドスタジオ 13.0.1
強(qiáng)力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック

複數(shù)のモニターを備えたMacを使用している場(chǎng)合、すべての畫面にドックを表示する方法や、ドックをセカンダリディスプレイに追加できるかどうかに興味があるかもしれません。

長年にわたって複數(shù)のAppleデバイスを所有している場(chǎng)合、これらの古いMac、iPhone、iPad、またはその他のAppleハードウェアの一部が販売、配信、または取引されている狀況にいる場(chǎng)合があります。彼らがどのようにあなたの所有物を離れても、それはそうです

FortniteはiPhoneユーザーとiPadユーザーが再び利用できるようになり、多くのゲーマーに喜びをもたらします。ただし、Macの公式バージョンはまだありません(少なくともまだ)。それにもかかわらず、Apple Silicon Macの所有者は完全に運(yùn)が悪いわけではありません。iOS/iを?qū)g行できます

iCloudプライベートリレーは、iCloudサブスクリプションに含まれる優(yōu)れたプライバシー機(jī)能です。オンラインアクティビティとブラウジングを保護(hù)し、IPアドレスをマスキングし(一時(shí)的なアドレスを使用)、DNSルックアップを暗號(hào)化するように設(shè)計(jì)されています。これにより、3番目のPAが防止されます

畫面時(shí)間を使用して、子供のMacの使用法を管理していますか?はいの場(chǎng)合、アプリの制限を設(shè)定したり、Macのダウンタイムをスケジュールするなどを可能にしていることをすでに知っている可能性があります。さらに、アクセス可能なままの特定のアプリを選択することもできます

MacOS Sequoiaは、iPhoneミラーリングなどの印象的な機(jī)能をもたらす堅(jiān)実なオペレーティングシステムであり、パフォーマンスは多くのユーザーにとって優(yōu)れていますが、誰もが同じレベルの速度を経験するわけではありません。 Macos SecoiaがPreよりも遅いと感じている場(chǎng)合

iMessageを頻繁に使用する場(chǎng)合、チャットで多數(shù)のWebリンクを共有している可能性があります。これは、記事、ビデオ、ツイート、曲などを共有しています。これらのリンクを後で見つけるのは非常にイライラすることがありますが、ありがたいことに、より簡(jiǎn)単な方法があります

コマンドラインに精通している高度なMacユーザーは、タルトを使用して端末にいくつかのコマンドを入力することにより、Macos Tahoe 26ベータ仮想マシンを迅速にセットアップできます。 Tartは仮想マシンを管理するためのコマンドラインユーティリティであり、Quickeの1つを提供します
