특정 날짜 이전의 파일을 삭제하고 폴더 바로 아래의 파일을 제외합니다.

특정 날짜 이전의 파일을 삭제하고 폴더 바로 아래의 파일을 제외합니다.

airflow 하위 폴더에서 10일이 지난 모든 파일을 삭제하고 싶습니다.

다음 명령을 사용했습니다.

 find  /var/log/airflow/  -type f -mtime +10  -delete

그러나 airflow 폴더(file1, file2, file3, file4, file5) 아래에 있는 모든 파일은 제외됩니다.

pwd

/var/log/airflow

ls -ltr

drwxr-xr-x 2 root root 6 Sep 13 11:15 folder1
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder2
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder3
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder4
drwxr-xr-x 2 root root 6 Sep 13 11:15 folder5
-rw-r--r-- 1 root root 0 Sep 13 11:15 file1
-rw-r--r-- 1 root root 0 Sep 13 11:15 file2
-rw-r--r-- 1 root root 0 Sep 13 11:15 file3
-rw-r--r-- 1 root root 0 Sep 13 11:15 file4
-rw-r--r-- 1 root root 0 Sep 13 11:15 file5

따라서 airflow 아래의 모든 하위 폴더와 해당 파일은 지워지지만 Airflow 아래의 파일은 지워지지 않습니다. 이 경우 제외를 지원하도록 명령을 어떻게 변경할 수 있습니까?

답변1

당신이 해야 할 일은 다음과 같이 -minlength 전역 옵션을 추가하는 것뿐입니다.

$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10  -delete

답변2

/var/log/airflow의 하위 폴더만 보도록 지시하려면 find다음 시작점을 제공하면 됩니다.

shopt -s dotglob
find  /var/log/airflow/*/* -type f -mtime +10 -delete

이렇게 하면 /var/log/airflow 아래의 하위 디렉터리가 일치하게 됩니다. 공기 흐름 아래에 설정한 "숨겨진" 디렉터리 dotglob도 모두 일치합니다.

관련 정보