Error in deleting files or directories older than 1 day

The name of the pictureThe name of the pictureThe name of the pictureClash 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









share|improve this question























  • 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














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









share|improve this question























  • 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












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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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.






share|improve this answer






















  • 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. 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


















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





share|improve this answer






















  • 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 the ls -d /u01/Release/redis-3.2.11 output here
    – EBIN GLADSON
    Oct 4 at 10:21











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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.






share|improve this answer






















  • 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. 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















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.






share|improve this answer






















  • 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. 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













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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. 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

















  • 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. 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
















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













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





share|improve this answer






















  • 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 the ls -d /u01/Release/redis-3.2.11 output here
    – EBIN GLADSON
    Oct 4 at 10:21















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





share|improve this answer






















  • 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 the ls -d /u01/Release/redis-3.2.11 output here
    – EBIN GLADSON
    Oct 4 at 10:21













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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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 the ls -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











  • 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 the ls -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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?