LoginSignup
3
3

More than 5 years have passed since last update.

【Linux】指定ファイルをfindコマンドで検索する

Posted at

指定したファイル名のファイルを検索する

Linux系のシステムを使用しているとファイル検索は、ほぼ発生する。その際に覚えておきたいコマンドを備忘録に残しておく。

findコマンド

以下は指定ディレクトリに対して検索を実行する。

format.cmd
find [ディレクティブ] -name [ファイルシンボル]
example.cmd
$ find / -name *.pdf
./aaa.pdf

wcオプション

検索でヒットしたファイル数を表示するオプション

format.cmd
find / -name *.pdf | wc
       1       1      10

lsオプション

検索でヒットしたファイルの情報を確認したい場合

find / -name *.pdf -ls
35743018        8 -rw-r--r--    1 root   staff   4  1  4 12:35 ./aaa.pdf

備考

・ルートなディレクトリでは上記コマンドを実行する際に、sudoオプションをつけるか、スーパユーザになっておく必要がある
・検索のコストを下げるために、 [ * ] よりも [ *.pdf ] など拡張子を指定してあげると良い

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3