~5k 미만의 파일 삭제

~5k 미만의 파일 삭제

나에게는 12명의 이사가 있다.

/home/imp/hpt/boxes/110.110.2.0/
/home/imp/hpt/boxes/115.115.16.0
/home/imp/hpt/boxes/1.154.10.0/
/home/imp/hpt/boxes/44.100.0.0/
/home/imp/hpt/boxes/46.1.100.0/

/home/imp/hpt/outbound/
/home/imp/hpt/outbound.002/
/home/imp/hpt/outbound.02c/
/home/imp/hpt/outbound.02e/
/home/imp/hpt/outbound.06e/
/home/imp/hpt/outbound.073/
/home/imp/hpt/outbound.38f/

각 디렉토리에서 5k 미만의 파일을 삭제하고 싶습니다. 이 파일은 숫자 *.mo? *.tu? *.we? *.th? *.fr? *.sa? *su?부터?09

나는 그것에 대해 읽었 inotifywait으며 이것을 달성하기 위해 그것을 사용할 수 있는지 궁금합니다. 가능합니까?

감사해요.

편집: 좋습니다. 제가 작성하려는 스크립트는 다음과 같습니다 inotifywait. 보시다시피, 저는 그리 멀리 가지 못했습니다.

#!/bin/bash

dir1=/home/imp/hpt/boxes/110.110.2.0/
dir2=/home/imp/hpt/boxes/115.115.16.0/
dir3=/home/imp/hpt/boxes/1.54.10.0/
dir4=/home/imp/hpt/boxes/44.100.0.0/
dir5=/home/imp/hpt/boxes/46.1.100.0/
dir6=/home/imp/hpt/outbound/
dir7=/home/imp/hpt/outbound.002/
dir8=/home/imp/hpt/outbound.02c/
dir9=/home/imp/hpt/outbound.02e/
dir10=/home/imp/hpt/outbound.06e/
dir11=/home/imp/hpt/outbound.073/
dir12=/home/imp/hpt/outbound.38f/

inotifywait --daemon --outfile /home/imp/hpt/remove.log -m "$dir1" "$dir2" "$dir3" "$dir4" "$dir5" "$dir6" "$dir7" "$dir8" "$dir10" "$dir11" "$dir12" -e     delete |
    while read path action file; do
        for name in "$dir1'" "$dir2" "$dir3" "$dir4" "$dir5" "$dir6" "$dir7" "$dir8" "$dir9" "$dir10" "$dir11" "$dir12"

누구든지 나를 도와줄 수 있나요?

답변1

find . \( -name '*.mo[0-9]' -o -name '*.tu[0-9]' \) -size -5120c -delete

을 사용할 수도 있지만 size -5k어리석은 find반올림을 수행하므로 정확도가 떨어집니다.

그러나 크기는 다음 단위로 반올림된다는 점을 명심하십시오(따라서 1바이트 파일은 -size -1M과 일치하지 않습니다).

답변2

inotify그리고 inotifywait실시간으로 파일 시스템 작업을 모니터링합니다. 생성된 파일을 캡처하는 데 사용할 수 있지만 이미 존재하는 파일을 찾는 데는 도움이 될 수 없습니다.

나는 당신이 기존 파일을 찾고 싶다고 가정합니다. GNU find를 사용하면 정규식 패턴을 사용하여 이를 찾는 표현식을 약간 압축할 수 있습니다.

$ find -type f -size -5120c -regextype awk -regex ".*\.(mo|tu|we|th|fr|sa|su)[0-9]" -delete

(크기는 5120바이트이며 필요에 따라 조정합니다.)

관련 정보