0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

findコマンドでファイル検索

Last updated at Posted at 2022-10-05

コピペ用

/:ルートディレクトリ
~:ホームディレクトリ

検索
find / ファイル名 2>/dev/null
ファイル検索
find ~ -type f -name ファイル名 2>/dev/null
ディレクトリ検索
find ~ -type d -name ディレクトリ名 2>/dev/null
$ find ~ -name sample.py 2>/dev/null
$ find ~/Desktop -type f -name "*開発キックオフ*" 2>/dev/null

*はワイルドカード。部分一致検索ができるので便利。

ルートディレクトリは、ファイルシステムのトップレベルに位置するディレクトリです。
上手くいかない場合は、権限があるかどうか確認してください。(例:ls -lrt

わざわざルートディレクトリで検索する必要がない場合や、権限がない場合は、ホームディレクトリでの検索に変更したり、コマンドの先頭にsudoを付けて試してみるのも一つの手段です。

また、Macのシステム環境設定>セキュリティとプライバシー>ファイルとフォルダ>iTermの設定が有効であることもご確認ください。

2>/dev/nullを付け足すことで余計な出力をなくしている

Before
(base) sample@SampleMBP Selenium % find / -name "*自動*"
find: /usr/sbin/authserver: Permission denied
find: /Library/Application Support/Apple/ParentalControls/Users: Permission denied
find: /Library/Application Support/Apple/AssetCache/Data: Permission denied
find: /Library/Application Support/ApplePushService: Permission denied
find: /Library/Application Support/com.apple.TCC: Operation not permitted
find: /Library/Caches/com.google.SoftwareUpdate.0: Permission denied
find: /Library/Caches/com.apple.iconservices.store: Permission denied
find: /Library/Caches/com.apple.aned: Operation not permitted

省略

コマンドに2>/dev/nullがない場合、Permission deniedなど欲しくない情報まで出力され、探すのが煩わしい


After
(base) sample@SampleMBP ~ % find / -name "*自動*" 2>/dev/null
/Users/username/Documents/Python/Webスクレイピング/JupyterLab/BeautifulSoup/全自動ランキングデータ抽出コード.ipynb
/Users/username/Documents/Python/Webスクレイピング/JupyterLab/BeautifulSoup/全自動画像取得&保存コード.ipynb

標準エラー出力を/dev/nullという特別な場所に捨て去ってくれる

参考

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?