내 친구는 -r 스위치를 사용하여 디렉터리와 하위 디렉터리에서 반복적으로 파일을 찾을 수 있다고 들었습니다. 주어진 명령문의 오류가 작동하지 않는지 알려주세요.
find / -type f -r -name "abc.txt"
답변1
작동하지 않는 이유는 find에 -r
옵션이 없기 때문입니다. 많은 프로그램에서 플래그가 '재귀'를 의미하는 것은 사실이지만 -r
모든 프로그램에 해당되는 것은 아니며 find
. 의 작업은 find
파일과 디렉터리를 검색하는 것입니다.~하지 않다재귀적이기를 원합니다.
명령 을 사용하면 대부분의 프로그램의 옵션을 확인할 수 있습니다 man
. 예를 들어, man find
. find 매뉴얼이 방대하기 때문에 옵션을 검색해 볼 수도 있습니다 -r
.
$ man find | grep -w -- -r
-- 옵션은 grep에게 옵션 읽기를 중지하라고 지시합니다. 그렇지 않으면 -r이 grep에 옵션으로 전달됩니다. 또한 매뉴얼 페이지 내에서 /
검색하려는 내용을 누른 다음 입력하여 검색할 수 있습니다.
해당 명령은 아무것도 반환하지 않습니다. 다음 설명서를 검색하는 명령과 비교해 보세요 cp
.
$ man cp | grep -w -- -r
-R, -r, --recursive
항상 재귀 적이므로 find
하위 디렉터리 수를 선택할 수 있는 플래그인 역이 있습니다.
-maxdepth levels
Descend at most levels (a non-negative integer) levels of direc‐
tories below the command line arguments. -maxdepth 0
means only apply the tests and actions to the command line
arguments.
-mindepth levels
Do not apply any tests or actions at levels less than levels (a
non-negative integer). -mindepth 1 means process all files
except the command line arguments.
따라서 명령에 대해 의문이 있을 때마다 man
특정 옵션의 기능이 무엇인지 알 수 없으므로 해당 페이지를 읽으십시오. 예를 들어:
$ man sort | grep -w -- -r
-r, --reverse
$ man mount | grep -w -- -r,
-r, --read-only
$ man awk | grep -A 8 -w -- -r
-r
--re-interval
Enable the use of interval expressions in regular expression
matching (see Regular Expressions, below). Interval expressions
were not traditionally available in the AWK language. The POSIX
standard added them, to make awk and egrep consistent with each
other. They are enabled by default, but this option remains for
use with --traditional.
$ man sed | grep -w -- -r
-r, --regexp-extended
$ man xterm | grep -w -- -r
-r This option indicates that reverse video should be simulated by
swapping the foreground and background colors.
당신은 아이디어를 얻습니다.
답변2
find
이미 재귀적이므로 필요하지 않습니다.-r