Rust で作成された、非常に意見の多い簡素化された Find コマンド。
デフォルトでは、作業ディレクトリ内のファイル/フォルダーを検索し、結果を完全一致とクエリのみを含むものに分割します。
結果はアルファベット順に並べ替えられます。
たとえば、 hunt SomeFile /
ルート ディレクトリから「SomeFile」を検索し、出力は次のようになります。
Contains:
/SomeFileIsHere
/home/lyon/Downloads/abcdefgSomeFileeee
/mnt/Files/--SomeFile--
Exact:
/home/lyon/SomeFile
他のツールとの比較については、ベンチマークを確認してください。
hunt [OPTIONS] [NAME] [SEARCH_IN_DIRS]...
デフォルトでは、 [NAME]
に大文字が含まれているか、 --case-sensitive
フラグが設定されている場合を除き、検索では大文字と小文字が区別されません。
-f, --first
Stop when first occurrence is found
-e, --exact
Only search for exactly matching occurrences, any file only containing the query will be skipped
e.g. if query is "SomeFile", "I'mSomeFile" will be skipped, as its name contains more letters than the search
-c, --canonicalize
If enabled, all paths will be canonicalized
-C, --case-sensitive
If enabled, the search will be case-sensitive
Note that case-sensitivity will be activated automatically when the search query contains an uppercase letter
-v, --verbose
Print verbose output
It'll show all errors found: e.g. "Could not read /proc/81261/map_files"
-s, --simple...
Prints without formatting (without "Contains:" and "Exact:")
-ss Output is not sorted
-H, --hidden
If enabled, it searches inside hidden directories
If not enabled, hidden directories will be skipped
--select
When the search is finished, choose one file between the results
The selected file will be printed as if -ss was used
--multiselect
When the search is finished, choose between the results
The selected files will be printed one after the other, separated by spaces
-S, --starts <STARTS_WITH>
Only files that start with this will be found
-E, --ends <ENDS_WITH>
Only files that end with this will be found
-t, --type <FILE_TYPE>
Specifies the type of the file
'f' -> file | 'd' -> directory
-i, --ignore <IGNORE_DIRS>
Ignores this directories. The format is:
-i dir1,dir2,dir3,...
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
--first
フラグが設定されている場合、ファイルは[current_dir, home_dir, root]
の順序で検索されます。
すでにこれらのディレクトリのいずれかに存在している場合、 current_dir
スキップされます。
--hidden
フラグが設定されていない場合、隠しファイル/ディレクトリはスキップされます。
[NAME] Name of the file/folder to search
By default, searches are case-insensitive, unless the query contains an uppercase letter.
[SEARCH_IN_DIRS]...
Directories where you want to search
If provided, hunt will only search there
These directories are treated independently, so if one is nested into another the
search will be done two times:
e.g. "hunt somefile /home/user /home/user/downloads" will search in the home
directory, and because /home/user/downloads is inside it, /downloads will be
traversed two times
システム全体で特定のファイルを検索します (見つかると検索は停止します)
hunt -f -e SomeFile
「SomeFile」を含むファイルを検索する
hunt SomeFile
ホームディレクトリ内のファイルを検索
hunt -e SomeFile ~/
ダウンロードおよび画像ディレクトリ内のファイルを検索します
hunt -e SomeFile ~/downloads ~/pictures
「.exe」で終わるすべてのファイルを検索します
hunt --ends .exe
wine ディレクトリ内の「.exe」で終わるすべてのファイルを検索します
hunt --ends .exe ~/.wine
「.」で始まるすべてのファイルを検索します。 (すべての隠しファイル)
hunt --starts .
wine ディレクトリ内で「.exe」で終わり、「M」で始まり「wind」を含むすべてのファイルを検索します。
hunt --starts=M --ends=.exe wind ~/.wine
「folder」という名前のディレクトリを検索します
hunt -t=d folder
「notfolder」という名前のファイルを検索します
hunt -t=f notfolder
「SomeFile」という名前のファイルをすべて削除します
hunt -s -e SomeFile | xargs rm -r
通常、ファイルを検索するとき、それがどこにあるのか正確なサブディレクトリがわからないので、最終的には $HOME ディレクトリ全体を検索することになります。
このためにfind
コマンドを使用すると、すべてのディレクトリを走査するのに時間がかかり、出力も読みづらかったため、非常に遅くなりました。
locate
高速でしたが、リアルタイムで更新されないデータベースのみを検索するため、探しているファイルが常に見つかるとは限りませんでした。
find
並列処理をまったく実行しないことを見て、マルチスレッド バージョンを作成することに決め、Hunt が誕生しました。
Hunt はマルチスレッドであるため、 find
よりもはるかに高速で、 locate
よりも信頼性が高くなります (最近のファイルは見つかりません)。
リリースから最新のバイナリをダウンロードします。
または、 cargo-binstall
を使用してインストールします。
cargo binstall hunt
まずRustがインストールされていることを確認してから実行します
cargo install hunt
Hunt を、最も使用されているツールのいくつかと比較してみましょう。GNU のlocateおよびfindと、同じく Rust で書かれた非常に人気のあるfd です。
ベンチマークには、fd dev が開発したツール、hyperfine を使用しています。
これらは、ネットワーク ドライブと外部ドライブを備えた、約 2,762,223 個のファイルを備えたシステムで実行されます。
他のシステムでは結果が異なる場合があるため、この比較はガイドとしてご利用ください。
ベンチマークを再現したい場合は、このリポジトリからbenchmarks.sh
ファイルを実行して実行できます。
ホーム ディレクトリの隠しフォルダー内で、高度にネストされたファイルの最初の出現を見つけます。ファイルは/home/user/.wine/drive_c/users/user/AppData/Local/mygame/User Data/Crashpad/reports/SomeFile
にあります。
Benchmark 1: hunt --hidden --first --exact SomeFile ~/
Time (mean ± σ): 180.2 ms ± 7.4 ms [User: 406.6 ms, System: 1135.9 ms]
Range (min … max): 167.2 ms … 198.5 ms 16 runs
Benchmark 2: fd --hidden --no-ignore --glob --color=never --max-results=1 SomeFile ~/
Time (mean ± σ): 913.6 ms ± 52.5 ms [User: 2584.8 ms, System: 4628.6 ms]
Range (min … max): 858.6 ms … 1018.6 ms 10 runs
Benchmark 3: find ~/ -name SomeFile -print -quit 2>/dev/null
Time (mean ± σ): 2.219 s ± 0.071 s [User: 0.587 s, System: 0.988 s]
Range (min … max): 2.160 s … 2.395 s 10 runs
Benchmark 4: locate -n 1 -A SomeFile
Time (mean ± σ): 1.244 s ± 0.015 s [User: 1.231 s, System: 0.010 s]
Range (min … max): 1.231 s … 1.281 s 10 runs
Summary
'hunt --hidden --first --exact SomeFile ~/' ran
5.07 ± 0.36 times faster than 'fd --hidden --no-ignore --glob --color=never --max-results=1 SomeFile ~/'
6.90 ± 0.30 times faster than 'locate -n 1 -A SomeFile'
12.31 ± 0.64 times faster than 'find ~/ -name SomeFile -print -quit 2>/dev/null'
--hidden、すべてのファイルを検索します (通常、無視リスト内の隠しファイルとディレクトリは無視されます)。
--first、最初の出現が見つかったときに停止します。
--exact、「SomeFile」という名前のファイル/フォルダーのみを検索します。パターンのみを含む名前はスキップされます。
ルート ディレクトリから「SomeFile」をすべて検索します (最悪の場合、システム内のすべてのファイルを確認します)。
問題の出来事は次のとおりです。
/home/lyon/Downloads/abcdefgSomeFileeee
/SomeFileIsHere
/mnt/Files/--SomeFile--
/home/lyon/.wine/drive_c/Program Files (x86)/Internet Explorer/SomeFile
このベンチマークでは、Locate は省略します。データベースによってバックアップされるため、すべてのファイルシステムを走査するわけではないため、明らかに高速です。
ただし、データベースは他のドライブにあるファイルの記録を保持していないため、/mnt/Files にファイルが見つからなかったことに注意する必要があります。
興味深いことに、このタイムは 486.8 ミリ秒で、ハントのわずか 1.32 倍でした。
Benchmark 1: hunt -H SomeFile /
Time (mean ± σ): 633.6 ms ± 25.1 ms [User: 2876.7 ms, System: 2507.5 ms]
Range (min … max): 589.4 ms … 671.2 ms 10 runs
Benchmark 2: fd -HI -c never SomeFile /
Time (mean ± σ): 1.452 s ± 0.014 s [User: 4.116 s, System: 8.693 s]
Range (min … max): 1.431 s … 1.474 s 10 runs
Benchmark 3: find / -name "*SomeFile*"
Time (mean ± σ): 3.473 s ± 0.144 s [User: 1.234 s, System: 1.602 s]
Range (min … max): 3.374 s … 3.874 s 10 runs
'hunt -H SomeFile /' ran
2.29 ± 0.09 times faster than 'fd -HI -c never SomeFile /'
5.48 ± 0.31 times faster than 'find / -name "*SomeFile*"'
多くの機能 (正規表現など) が必要ない場合、Hunt は他の代替手段よりも高速です。
単純に「そのファイルをどこに置いた?」と考えてください。解決。