0

I would like to delete all files that older than 10 days from airflow sub folders

I used the following command:

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

but excluding all the files that exist under airflow folder as: 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

so all sub folders under airflow with their files will be effaced but not the files under airflow. In that case how can I change my command to support the excluding.

3

all you need to do is add the -mindepth global option like this:

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

To tell find to look only in subfolders of /var/log/airflow, just give it those starting points:

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

This forces a subdirectory to exist under /var/log/airflow in order to match. I set dotglob so that any "hidden" directories under airflow are also matched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.