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가 탄생했습니다.
Hunt는 멀티스레드이므로 find
보다 훨씬 빠르고, locate
보다 더 안정적입니다(최근 파일은 찾을 수 없습니다).
릴리스에서 최신 바이너리를 다운로드하세요.
또는 cargo-binstall
로 설치하십시오:
cargo binstall hunt
먼저 Rust가 설치되어 있는지 확인한 다음 다음을 실행하세요.
cargo install hunt
Hunt를 가장 많이 사용되는 도구인 GNU 찾기 및 찾기 와 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의 파일을 찾을 수 없다는 점에 유의해야 합니다.
궁금하신 분들은 Hunt보다 1.32배 빠른 486.8ms의 시간을 기록했습니다.
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가 다른 대안보다 빠릅니다.
간단히 "그 파일을 어디에 넣었나요?"라고 생각해보세요. 해결책.