특정 폴더 내에서 2MB보다 큰 파일을 삭제하고 싶었습니다. 그래서 나는 달렸다.
find . -size +2M
그리고 나는 두 파일의 목록을 얻었다
./a/b/c/file1
./a/f/g/file2
그래서 나는 다음을 실행합니다.
find . -size +2M -exec rm ;
오류 메시지가 나타납니다 Find: missing argument to -exec
맨 페이지에서 구문을 확인하면 -exec command ;
대신에 나는 시도
find . -size +2M -exec rm {} +
그리고 작동합니다. {}이 (가) rm file1 file2
대신 명령을 실행한다는 것을 이해합니다 rm file1; rm file2;
.
왜 첫 번째가 효과가 없었습니까?
대답:
나는 그것이 무슨 말을했는지 마침내 이해하기 위해 RTFM을 두 번해야했다고 생각합니다. 첫 번째 예에 {}가 표시되지 않더라도 모든 경우에 중괄호가 필요합니다. 그런 다음 \를 추가하십시오. 또는 원하는 방법에 따라 + 제목 만 읽지 마십시오. 설명도 읽으십시오. 알았다.
답변
다음 형식 중 하나를 사용할 수 있습니다.
find . -size +2M -exec rm {} +
find . -size +2M -exec rm {} \;
세미콜론은 탈출해야합니다!
답변
-exec rm {} \;
당신은 사용할 수 있습니다 .. 남자 찾기
-exec command ;
Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until
an argument consisting of `;' is encountered. The string `{}' is replaced by the current file name being processed everywhere
it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these
constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell. See the EXAMPLES
section for examples of the use of the -exec option. The specified command is run once for each matched file. The command is
executed in the starting directory. There are unavoidable security problems surrounding use of the -exec action; you should
use the -execdir option instead.
-exec command {} +
This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending
each selected file name at the end; the total number of invocations of the command will be much less than the number of matched
files. The command line is built in much the same way that xargs builds its command lines. Only one instance of `{}' is
allowed within the command. The command is executed in the starting directory.
답변
효율성을 위해 일반적으로 xargs를 사용하는 것이 좋습니다.
$ find /path/to/files -size +2M -print0 | xargs -0 rm