Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of deleting files older than a specific day and excluding the direct files under folder without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
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.
Answer
all you need to do is add the -mindepth global option like this:
$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete
We are here to answer your question about deleting files older than a specific day and excluding the direct files under folder - If you find the proper solution, please don't forgot to share this with your team members.