Perintah Find sederhana yang dibuat dengan Rust.
Secara default, ia mencari file/folder di direktori kerja dan membagi hasilnya antara yang sama persis dan yang hanya berisi kueri.
Hasil akan diurutkan berdasarkan abjad.
Misalnya, hunt SomeFile /
akan mencari "SomeFile" dari direktori root, dan hasilnya bisa berupa:
Contains:
/SomeFileIsHere
/home/lyon/Downloads/abcdefgSomeFileeee
/mnt/Files/--SomeFile--
Exact:
/home/lyon/SomeFile
Periksa Tolok Ukur untuk perbandingan dengan alat lainnya.
hunt [OPTIONS] [NAME] [SEARCH_IN_DIRS]...
Secara default, penelusuran tidak peka huruf besar-kecil, kecuali [NAME]
berisi huruf besar atau tanda --case-sensitive
disetel.
-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
Jika tanda --first
disetel, urutan pencarian file adalah [current_dir, home_dir, root]
.
Jika Anda sudah berada di salah satu direktori ini, current_dir
akan dilewati.
Jika tanda --hidden
tidak disetel, file/direktori tersembunyi akan dilewati.
[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
Cari file tertentu di seluruh sistem (perburuan akan berhenti setelah ditemukan)
hunt -f -e SomeFile
Cari file yang mengandung "SomeFile"
hunt SomeFile
Cari file di direktori home
hunt -e SomeFile ~/
Cari file di direktori unduhan dan gambar
hunt -e SomeFile ~/downloads ~/pictures
Cari semua file yang diakhiri dengan ".exe"
hunt --ends .exe
Cari semua file yang diakhiri dengan ".exe" di direktori wine
hunt --ends .exe ~/.wine
Cari semua file yang dimulai dengan "." (semua file tersembunyi)
hunt --starts .
Cari semua file yang diakhiri dengan ".exe", dimulai dengan "M" dan berisi "wind" di direktori wine
hunt --starts=M --ends=.exe wind ~/.wine
Cari direktori bernama "folder"
hunt -t=d folder
Cari file bernama "notfolder"
hunt -t=f notfolder
Hapus semua file bernama "SomeFile"
hunt -s -e SomeFile | xargs rm -r
Biasanya ketika saya mencari file, saya tidak tahu persis subdirektorinya, jadi saya akhirnya mencari di seluruh direktori $HOME.
Menggunakan perintah find
untuk ini ternyata sangat lambat, karena memerlukan banyak waktu untuk melintasi semua direktori, dan hasilnya juga sulit dibaca.
locate
lebih cepat, tetapi tidak selalu menemukan file yang saya cari, karena hanya mencari di database-nya yang tidak diperbarui secara real-time.
Melihat bagaimana find
tidak melakukan paralelisme sama sekali, saya memutuskan untuk membuat versi multithread, dan begitulah lahirnya Hunt.
Hunt bersifat multithread, sehingga jauh lebih cepat daripada find
, dan lebih dapat diandalkan daripada locate
(file terbaru tidak dapat ditemukan dengan itu).
Unduh biner terbaru dari rilis.
Atau instal dengan cargo-binstall
:
cargo binstall hunt
Pertama periksa apakah Anda telah menginstal Rust, lalu jalankan
cargo install hunt
Mari kita bandingkan Hunt dengan beberapa alat yang paling sering digunakan: GNU mencari dan menemukan dan yang sangat populer juga ditulis dalam karat, fd .
Untuk benchmarking saya menggunakan hyperfine, alat yang dikembangkan oleh fd dev.
Ini dilakukan dalam sistem dengan sekitar 2.762.223 file, dengan drive jaringan dan drive eksternal.
Hasil pada sistem lain mungkin berbeda, jadi gunakan perbandingan ini sebagai panduan.
Jika Anda ingin mereproduksi benchmark, Anda dapat melakukannya dengan menjalankan file benchmarks.sh
dari repositori ini.
Temukan kemunculan pertama file yang sangat bersarang di folder tersembunyi dari direktori home. File terletak di /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, cari semua file (biasanya mengabaikan file dan direktori tersembunyi di Daftar Abaikan).
--pertama, berhenti ketika kejadian pertama ditemukan.
--tepat, hanya cari file/folder bernama "SomeFile", nama yang hanya berisi pola akan dilewati.
Temukan semua kemunculan "SomeFile" dari direktori root (skenario terburuk, periksa semua file di sistem).
Kejadian yang dimaksud adalah:
/home/lyon/Downloads/abcdefgSomeFileeee
/SomeFileIsHere
/mnt/Files/--SomeFile--
/home/lyon/.wine/drive_c/Program Files (x86)/Internet Explorer/SomeFile
Untuk patokan ini saya akan melewatkan Locate. Ini jelas lebih cepat karena tidak melintasi seluruh sistem file, karena dicadangkan oleh database.
Perlu dicatat bahwa file di /mnt/Files tidak ditemukan, karena database tidak menyimpan catatan file di drive lain.
Bagi yang penasaran, ia mencetak waktu 486,8 ms, hanya 1,32 kali lebih cepat dari Hunt.
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 lebih cepat dibandingkan alternatif lain jika Anda tidak memerlukan banyak fitur (seperti regex).
Anggap saja sederhana "di mana saya meletakkan file itu?" larutan.