deleting files older than a specific day and excluding the direct files under folder
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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.
linux shell-script rhel find regular-expression
add a comment |Â
up vote
0
down vote
favorite
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.
linux shell-script rhel find regular-expression
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
linux shell-script rhel find regular-expression
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.
linux shell-script rhel find regular-expression
linux shell-script rhel find regular-expression
edited Sep 13 at 14:38
Goro
5,47052460
5,47052460
asked Sep 13 at 11:20
yael
2,0391345
2,0391345
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
all you need to do is add the -mindepth global option like this:
$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
all you need to do is add the -mindepth global option like this:
$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete
add a comment |Â
up vote
3
down vote
accepted
all you need to do is add the -mindepth global option like this:
$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
all you need to do is add the -mindepth global option like this:
$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete
all you need to do is add the -mindepth global option like this:
$ find /var/log/airflow/ -mindepth 2 -type f -mtime +10 -delete
answered Sep 13 at 11:45
B.McCready
663
663
add a comment |Â
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
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.
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.
answered Sep 13 at 12:33
Jeff Schaller
33.1k849111
33.1k849111
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468769%2fdeleting-files-older-than-a-specific-day-and-excluding-the-direct-files-under-fo%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password