أمر بحث مبسط وذو آراء عالية تم إنشاؤه باستخدام 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" في دليل النبيذ
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 متعدد الخيوط، لذا فهو أسرع بكثير من find
وأكثر موثوقية من locate
(لا يمكن العثور على الملفات الحديثة باستخدامه).
قم بتنزيل أحدث ثنائي من الإصدارات.
أو قم بالتثبيت باستخدام cargo-binstall
:
cargo binstall hunt
تأكد أولاً من تثبيت Rust، ثم قم بتشغيله
cargo install hunt
دعونا نقارن Hunt ببعض الأدوات الأكثر استخدامًا: GNU location and find والأداة المشهورة جدًا والمكتوبة أيضًا بالصدأ، fd .
لقياس الأداء، أستخدم أداة فائقة الدقة، وهي أداة تم تطويرها بواسطة 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'
- مخفي، ابحث في جميع الملفات (عادةً ما يتجاهل الملفات والأدلة المخفية في قائمة التجاهل).
--أولاً، توقف عند العثور على التواجد الأول.
--تمامًا، ابحث فقط عن الملفات/المجلدات المسماة "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 مللي ثانية، أي أسرع بـ 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 أسرع من البدائل الأخرى إذا كنت لا تحتاج إلى الكثير من الميزات (مثل التعبير العادي).
فكر في الأمر على أنه سؤال بسيط "أين وضعت هذا الملف؟" حل.