![찾기: "-exec가 0을 반환"할 때 "-printf만 표시"](https://linux55.com/image/190584/%EC%B0%BE%EA%B8%B0%3A%20%22-exec%EA%B0%80%200%EC%9D%84%20%EB%B0%98%ED%99%98%22%ED%95%A0%20%EB%95%8C%20%22-printf%EB%A7%8C%20%ED%91%9C%EC%8B%9C%22.png)
내가 가진 것:
/usr/bin/find /my_directory -type f -not -empty -name '*.log' -printf '%T@ %Tc %p\n' -exec grep 'text in file' {} \;
다음 위치에 비어 있지 않은 모든 로그 파일이 표시됩니다 /my_directory
.
1619942263.2701036230 Sun May 2 09:57:43 2021 /my_directory/abc.log
1619945861.8521817540 Sun May 2 10:57:41 2021 /my_directory/def.log
text in file
하지만 - 또는 비슷한 스타일의 파일 만 얻고 싶습니다 .
답변1
-exec
전에 넣어 -printf
:
find /my_directory -type f -not -empty -name '*.log' -exec grep -q 'text in file' {} \; -printf '%T@ %Tc %p\n'
-exec
명령이 0이 아닌 종료 코드로 종료되면 false로 평가되고 후속 작업을 건너뜁니다.