คำสั่ง Find ที่เรียบง่ายซึ่ง มีความคิดเห็นสูง ซึ่งสร้างด้วย Rust
ตามค่าเริ่มต้น ระบบจะค้นหาไฟล์/โฟลเดอร์ในไดเร็กทอรีการทำงาน และแบ่งผลลัพธ์ระหว่างรายการที่ตรงกันทุกประการกับรายการที่มีเฉพาะแบบสอบถามเท่านั้น
ผลลัพธ์จะถูกจัดเรียงตามตัวอักษร
ตัวอย่างเช่น 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
ค้นหาไฟล์ทั้งหมดที่ลงท้ายด้วย ".exe" ในไดเร็กทอรี wine
hunt --ends .exe ~/.wine
ค้นหาไฟล์ทั้งหมดที่ขึ้นต้นด้วย "." (ไฟล์ที่ซ่อนอยู่ทั้งหมด)
hunt --starts .
ค้นหาไฟล์ทั้งหมดที่ลงท้ายด้วย ".exe" เริ่มต้นด้วย "M" และมี "wind" ในไดเรกทอรีไวน์
hunt --starts=M --ends=.exe wind ~/.wine
ค้นหาไดเรกทอรีชื่อ "โฟลเดอร์"
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 ค้นหา และ ค้นหา และเครื่องมือที่ได้รับความนิยมอย่างมากก็เขียนด้วยสนิม fd
สำหรับการเปรียบเทียบฉันใช้ Hyperfine ซึ่งเป็นเครื่องมือที่พัฒนาโดย fd dev
สิ่งเหล่านี้ทำในระบบที่มีไฟล์ประมาณ 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 ค้นหาไฟล์ทั้งหมด (โดยปกติจะละเว้นไฟล์และไดเร็กทอรีที่ซ่อนอยู่ในรายการละเว้น)
--ขั้นแรก ให้หยุดเมื่อพบเหตุการณ์ครั้งแรก
--exact ค้นหาเฉพาะไฟล์/โฟลเดอร์ชื่อ "SomeFile" ชื่อที่มีเฉพาะรูปแบบเท่านั้นที่จะถูกข้าม
ค้นหาเหตุการณ์ทั้งหมดของ "SomeFile" จากไดเร็กทอรีราก (สถานการณ์กรณีที่เลวร้ายที่สุดคือการตรวจสอบไฟล์ทั้งหมดในระบบ)
เหตุการณ์ที่เป็นปัญหาคือ:
/home/lyon/Downloads/abcdefgSomeFileeee
/SomeFileIsHere
/mnt/Files/--SomeFile--
/home/lyon/.wine/drive_c/Program Files (x86)/Internet Explorer/SomeFile
สำหรับการวัดประสิทธิภาพนี้ ฉันจะข้ามการค้นหา เห็นได้ชัดว่าเร็วกว่าเพราะไม่ได้ข้ามระบบไฟล์ทั้งหมดเนื่องจากมีการสำรองโดยฐานข้อมูล
จะต้องสังเกตว่าไม่พบไฟล์ใน /mnt/Files เนื่องจากฐานข้อมูลไม่ได้เก็บบันทึกไฟล์ในไดรฟ์อื่น
สำหรับผู้ที่อยากรู้อยากเห็น มันทำเวลาได้ 486.8 มิลลิวินาที เร็วกว่า Hunt เพียง 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 เร็วกว่าทางเลือกอื่นๆ หากคุณไม่ต้องการฟีเจอร์มากมาย (เช่น regex)
คิดง่ายๆ ว่า "ฉันเอาไฟล์นั้นไปไว้ที่ไหน" สารละลาย.