![find를 사용하여 파일 목록을 필터링하는 방법이 있습니까?](https://linux55.com/image/128324/find%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%ED%8C%8C%EC%9D%BC%20%EB%AA%A9%EB%A1%9D%EC%9D%84%20%ED%95%84%ED%84%B0%EB%A7%81%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
내 결과는 locate --existing --regex
매우 빠르게 얻어졌습니다. 비슷한 프로세스를 find
수행하려면 몇 시간이 걸립니다. 이는 엄청난 양입니다.
find
이 파일 목록에 추가 필터를 적용하고 싶습니다 .
내가 찾은 유일한 지름길은 동일한 검색을 두 번 적용하는 것입니다. 먼저 :를 사용하여 이러한 파일이 포함된 디렉터리 목록을 가져온 locate
다음 비재귀적으로 실행합니다 find
.
# Abandoned Office temporary files
PATTERN='/foo/.+/~$[^/]+'
# locate doesn't re-enter the same path so sort before uniq is unnecessary.
# --existing is unnecessary, since locality of reference and thus
# performance and load are better when stat-ing the entries is done only
# once by `find`
locate --regex "$PATTERN" | xargs -d\\n -L1 dirname -- | uniq | \
while read -r path; do
find "$path" -maxdepth 0 -regex "$PATTERN" -type f -ctime +30 -exec rm '{}' ';'
done
이 작업을 수행하는 덜 복잡한 방법이 있습니까?