Error in deleting files or directories older than 1 day
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am able to delete files or directories older than 1 day using below command
find /u01/Release/* -mtime +1 -exec rm -r ;
but why I am getting error in the output of this command:
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
drwxrwxr-x 6 root root 309 Sep 21 2017 redis-3.2.11
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
after executing command
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
files find date rm
add a comment |Â
up vote
2
down vote
favorite
I am able to delete files or directories older than 1 day using below command
find /u01/Release/* -mtime +1 -exec rm -r ;
but why I am getting error in the output of this command:
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
drwxrwxr-x 6 root root 309 Sep 21 2017 redis-3.2.11
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
after executing command
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
files find date rm
It's not because a directory hasn't been modified in the last 10 years, that none of the files in it are recent. Modifying the content of a file doesn't modify the directory it's in. It's when you add or remove entries to/from a directory that the directory is modified. For instance/
is hardly ever modified. You wouldn't want to remove every file because/
is old.
â Stéphane Chazelas
Oct 4 at 10:36
When you say older than 1 day, do you mean at least 2 days old (which is what-mtime +1
checks) or more than 24 hour old?
â Stéphane Chazelas
Oct 4 at 10:41
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am able to delete files or directories older than 1 day using below command
find /u01/Release/* -mtime +1 -exec rm -r ;
but why I am getting error in the output of this command:
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
drwxrwxr-x 6 root root 309 Sep 21 2017 redis-3.2.11
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
after executing command
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
files find date rm
I am able to delete files or directories older than 1 day using below command
find /u01/Release/* -mtime +1 -exec rm -r ;
but why I am getting error in the output of this command:
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
drwxrwxr-x 6 root root 309 Sep 21 2017 redis-3.2.11
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
after executing command
ls -lrt
drwxr-xr-x 3 tomcat8 tomcat8 60 Oct 4 07:11 build_180
-rw-r--r-- 1 root root 1550452 Oct 4 15:23 redis-3.2.11.tar.gz
files find date rm
files find date rm
edited Oct 4 at 12:03
asked Oct 4 at 10:06
RAJ METRE
204
204
It's not because a directory hasn't been modified in the last 10 years, that none of the files in it are recent. Modifying the content of a file doesn't modify the directory it's in. It's when you add or remove entries to/from a directory that the directory is modified. For instance/
is hardly ever modified. You wouldn't want to remove every file because/
is old.
â Stéphane Chazelas
Oct 4 at 10:36
When you say older than 1 day, do you mean at least 2 days old (which is what-mtime +1
checks) or more than 24 hour old?
â Stéphane Chazelas
Oct 4 at 10:41
add a comment |Â
It's not because a directory hasn't been modified in the last 10 years, that none of the files in it are recent. Modifying the content of a file doesn't modify the directory it's in. It's when you add or remove entries to/from a directory that the directory is modified. For instance/
is hardly ever modified. You wouldn't want to remove every file because/
is old.
â Stéphane Chazelas
Oct 4 at 10:36
When you say older than 1 day, do you mean at least 2 days old (which is what-mtime +1
checks) or more than 24 hour old?
â Stéphane Chazelas
Oct 4 at 10:41
It's not because a directory hasn't been modified in the last 10 years, that none of the files in it are recent. Modifying the content of a file doesn't modify the directory it's in. It's when you add or remove entries to/from a directory that the directory is modified. For instance
/
is hardly ever modified. You wouldn't want to remove every file because /
is old.â Stéphane Chazelas
Oct 4 at 10:36
It's not because a directory hasn't been modified in the last 10 years, that none of the files in it are recent. Modifying the content of a file doesn't modify the directory it's in. It's when you add or remove entries to/from a directory that the directory is modified. For instance
/
is hardly ever modified. You wouldn't want to remove every file because /
is old.â Stéphane Chazelas
Oct 4 at 10:36
When you say older than 1 day, do you mean at least 2 days old (which is what
-mtime +1
checks) or more than 24 hour old?â Stéphane Chazelas
Oct 4 at 10:41
When you say older than 1 day, do you mean at least 2 days old (which is what
-mtime +1
checks) or more than 24 hour old?â Stéphane Chazelas
Oct 4 at 10:41
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
This is very well known issue. The problem is that find
first removes directory and then tries to process files inside it. A solution is to first deal with stuff inside directory and only then delete directory. That's what -depth
option is for, so:
find /u01/Release/* -depth -mtime +1 -exec rm -r ;
should do the trick. You may also be interested in the shorter form using -delete
action (which implies -depth
):
find /u01/Release/* -mtime +1 -delete
As always man find
is your friend.
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
1
It's-mtime +0
for files older than 24 hours
â Stéphane Chazelas
Oct 4 at 10:31
Note that when you remove a file from a directory, that updates its mtime. Ifa/b/c
is 1 minute old,a/b
5 days old anda
5 year old, then it will removea/b
(andc
in the process), but nota
.
â Stéphane Chazelas
Oct 4 at 10:35
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
add a comment |Â
up vote
0
down vote
Try the below, Better to use --force
which will delete files and directories.
find /u01/Release/* -mtime +1 -exec rm -rf ;
-r, -R, --recursive
remove directories and their contents recursively
-f, --force
ignore nonexistent files, never prompt
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
ok, that means no older files are available under the directory/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that message
â RAJ METRE
Oct 4 at 10:20
share thels -d /u01/Release/redis-3.2.11
output here
â EBIN GLADSON
Oct 4 at 10:21
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
This is very well known issue. The problem is that find
first removes directory and then tries to process files inside it. A solution is to first deal with stuff inside directory and only then delete directory. That's what -depth
option is for, so:
find /u01/Release/* -depth -mtime +1 -exec rm -r ;
should do the trick. You may also be interested in the shorter form using -delete
action (which implies -depth
):
find /u01/Release/* -mtime +1 -delete
As always man find
is your friend.
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
1
It's-mtime +0
for files older than 24 hours
â Stéphane Chazelas
Oct 4 at 10:31
Note that when you remove a file from a directory, that updates its mtime. Ifa/b/c
is 1 minute old,a/b
5 days old anda
5 year old, then it will removea/b
(andc
in the process), but nota
.
â Stéphane Chazelas
Oct 4 at 10:35
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
add a comment |Â
up vote
2
down vote
This is very well known issue. The problem is that find
first removes directory and then tries to process files inside it. A solution is to first deal with stuff inside directory and only then delete directory. That's what -depth
option is for, so:
find /u01/Release/* -depth -mtime +1 -exec rm -r ;
should do the trick. You may also be interested in the shorter form using -delete
action (which implies -depth
):
find /u01/Release/* -mtime +1 -delete
As always man find
is your friend.
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
1
It's-mtime +0
for files older than 24 hours
â Stéphane Chazelas
Oct 4 at 10:31
Note that when you remove a file from a directory, that updates its mtime. Ifa/b/c
is 1 minute old,a/b
5 days old anda
5 year old, then it will removea/b
(andc
in the process), but nota
.
â Stéphane Chazelas
Oct 4 at 10:35
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
add a comment |Â
up vote
2
down vote
up vote
2
down vote
This is very well known issue. The problem is that find
first removes directory and then tries to process files inside it. A solution is to first deal with stuff inside directory and only then delete directory. That's what -depth
option is for, so:
find /u01/Release/* -depth -mtime +1 -exec rm -r ;
should do the trick. You may also be interested in the shorter form using -delete
action (which implies -depth
):
find /u01/Release/* -mtime +1 -delete
As always man find
is your friend.
This is very well known issue. The problem is that find
first removes directory and then tries to process files inside it. A solution is to first deal with stuff inside directory and only then delete directory. That's what -depth
option is for, so:
find /u01/Release/* -depth -mtime +1 -exec rm -r ;
should do the trick. You may also be interested in the shorter form using -delete
action (which implies -depth
):
find /u01/Release/* -mtime +1 -delete
As always man find
is your friend.
edited Oct 4 at 10:29
answered Oct 4 at 10:23
jimmij
29.5k867101
29.5k867101
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
1
It's-mtime +0
for files older than 24 hours
â Stéphane Chazelas
Oct 4 at 10:31
Note that when you remove a file from a directory, that updates its mtime. Ifa/b/c
is 1 minute old,a/b
5 days old anda
5 year old, then it will removea/b
(andc
in the process), but nota
.
â Stéphane Chazelas
Oct 4 at 10:35
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
add a comment |Â
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
1
It's-mtime +0
for files older than 24 hours
â Stéphane Chazelas
Oct 4 at 10:31
Note that when you remove a file from a directory, that updates its mtime. Ifa/b/c
is 1 minute old,a/b
5 days old anda
5 year old, then it will removea/b
(andc
in the process), but nota
.
â Stéphane Chazelas
Oct 4 at 10:35
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
Thanks for explanation.
â RAJ METRE
Oct 4 at 10:27
1
1
It's
-mtime +0
for files older than 24 hoursâ Stéphane Chazelas
Oct 4 at 10:31
It's
-mtime +0
for files older than 24 hoursâ Stéphane Chazelas
Oct 4 at 10:31
Note that when you remove a file from a directory, that updates its mtime. If
a/b/c
is 1 minute old, a/b
5 days old and a
5 year old, then it will remove a/b
(and c
in the process), but not a
.â Stéphane Chazelas
Oct 4 at 10:35
Note that when you remove a file from a directory, that updates its mtime. If
a/b/c
is 1 minute old, a/b
5 days old and a
5 year old, then it will remove a/b
(and c
in the process), but not a
.â Stéphane Chazelas
Oct 4 at 10:35
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
@StéphaneChazelas Yes, sure, I bet star glob is most probably also not what OP needs, but that's other topic.
â jimmij
Oct 4 at 10:38
add a comment |Â
up vote
0
down vote
Try the below, Better to use --force
which will delete files and directories.
find /u01/Release/* -mtime +1 -exec rm -rf ;
-r, -R, --recursive
remove directories and their contents recursively
-f, --force
ignore nonexistent files, never prompt
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
ok, that means no older files are available under the directory/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that message
â RAJ METRE
Oct 4 at 10:20
share thels -d /u01/Release/redis-3.2.11
output here
â EBIN GLADSON
Oct 4 at 10:21
add a comment |Â
up vote
0
down vote
Try the below, Better to use --force
which will delete files and directories.
find /u01/Release/* -mtime +1 -exec rm -rf ;
-r, -R, --recursive
remove directories and their contents recursively
-f, --force
ignore nonexistent files, never prompt
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
ok, that means no older files are available under the directory/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that message
â RAJ METRE
Oct 4 at 10:20
share thels -d /u01/Release/redis-3.2.11
output here
â EBIN GLADSON
Oct 4 at 10:21
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Try the below, Better to use --force
which will delete files and directories.
find /u01/Release/* -mtime +1 -exec rm -rf ;
-r, -R, --recursive
remove directories and their contents recursively
-f, --force
ignore nonexistent files, never prompt
Try the below, Better to use --force
which will delete files and directories.
find /u01/Release/* -mtime +1 -exec rm -rf ;
-r, -R, --recursive
remove directories and their contents recursively
-f, --force
ignore nonexistent files, never prompt
edited Oct 4 at 10:16
answered Oct 4 at 10:11
EBIN GLADSON
3316
3316
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
ok, that means no older files are available under the directory/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that message
â RAJ METRE
Oct 4 at 10:20
share thels -d /u01/Release/redis-3.2.11
output here
â EBIN GLADSON
Oct 4 at 10:21
add a comment |Â
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
ok, that means no older files are available under the directory/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that message
â RAJ METRE
Oct 4 at 10:20
share thels -d /u01/Release/redis-3.2.11
output here
â EBIN GLADSON
Oct 4 at 10:21
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
i tried that but still get this message find: âÂÂ/u01/Release/redis-3.2.11âÂÂ: No such file or directory
â RAJ METRE
Oct 4 at 10:13
ok, that means no older files are available under the directory
/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
ok, that means no older files are available under the directory
/u01/Release/redis-3.2.11
â EBIN GLADSON
Oct 4 at 10:15
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that messageâ RAJ METRE
Oct 4 at 10:20
/u01/Release/redis-3.2.11
this is older directory. it is deleting that directory with that messageâ RAJ METRE
Oct 4 at 10:20
share the
ls -d /u01/Release/redis-3.2.11
output hereâ EBIN GLADSON
Oct 4 at 10:21
share the
ls -d /u01/Release/redis-3.2.11
output hereâ EBIN GLADSON
Oct 4 at 10:21
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%2f473187%2ferror-in-deleting-files-or-directories-older-than-1-day%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
It's not because a directory hasn't been modified in the last 10 years, that none of the files in it are recent. Modifying the content of a file doesn't modify the directory it's in. It's when you add or remove entries to/from a directory that the directory is modified. For instance
/
is hardly ever modified. You wouldn't want to remove every file because/
is old.â Stéphane Chazelas
Oct 4 at 10:36
When you say older than 1 day, do you mean at least 2 days old (which is what
-mtime +1
checks) or more than 24 hour old?â Stéphane Chazelas
Oct 4 at 10:41