Finding files with find · find でファイルを探す
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Searching the whole tree
lsshows one folder.findsearches a folder and everything inside it, however deep:
.means "start in the current folder".findlists every file and folder it can reach.
日本語
木全体を検索する
lsは1つのフォルダを表示します。findはフォルダとその中身すべてを、深さに関わらず検索します:
find .
.は「現在のフォルダから始める」ことを意味します。findは到達可能なすべてのファイルとフォルダをリストアップします。
English
Find by name
- Usually you want files matching a pattern. Use
-name:
- This finds every
.txtfile in the tree — even ones buried three folders down. - Quote the pattern (
"*.txt") so the shell passes it tofinduntouched.
日本語
名前で探す
- 通常、パターンに一致するファイルを探したい場合、
-nameを使用します:
find . -name "*.txt"
- これは木内のあらゆる
.txtファイルを探します — フォルダを3つ下にあるものでも。 - パターンを引用符で囲み(
"*.txt")、シェルがfindにそのまま渡せるようにします。
English
Why it is handy
- "Where did I put that file?" —
findanswers it in one line. - Combined with pipes, you can act on the results — for example count them with
wc -l.
日本語
便利である理由
- 「あのファイルはどこに置いた?」 —
findで1行で回答できます。 - パイプと併用すると結果に対する操作が可能 — 例えば
wc -lで数え上げたりします。
English
Common mistakes
find . -name "*.txt"searches by name from the current folder down.- Quote the pattern so the shell does not expand it first.
日本語
よくあるミス
find . -name "*.txt"は現在のフォルダから下へ名前で検索します。- パターンを引用符で囲んで、シェルが最初に展開しないようにします。
Explore · 探索
find walks the tree · find がツリーを探索する
find searches the whole tree below a directory. · find はディレクトリ以下のツリー全体を検索する。
Find every .txt file, even deep inside subfolders, with find . -name "*.txt". (. means "start from here".) · .txt ファイルをサブフォルダの奥深くを含めてすべて見つけ、find . -name "*.txt" を使用します。(. は「ここから始めよ」を意味します。)
You can also start the search from a subfolder. Find just the .txt files inside docs (and below) with find docs -name "*.txt". · 検索を サブフォルダ から始めることもできます。.txt ファイルだけを docs 内部(および以下)で find docs -name "*.txt" で探す。