LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-24-2015, 09:17 AM   #1
xombboxer
Member
 
Registered: Apr 2011
Posts: 63

Rep: Reputation: 0
find 30 days old and delete prints error msg file not found after deleting it


I have a shell script to find folders which are 25 days older and delete it, and put the deleted folder details into log file like this

Code:
 find /ahome/xxx/$FOLDER -type d -mtime +25  -exec ls -ld {} \;  -exec rm -rf {} \;  >> mylogfile.log
after running this command it deletes the folder and logs the folder deleted. But also print error msg
Code:
find: /ahome/prksh/dir/test: No such file or directory
How to suppress the error msg
 
Old 02-24-2015, 01:14 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
When the action is to delete things, you need to include the "-depth" option so that tar will act on the deeper parts of the tree first rather than deleting a directory it just found and then trying to recurse into it.
Code:
find /ahome/xxx/$FOLDER -depth -type d -mtime +25  -exec ls -ld {} \;  -exec rm -rf {} \;  >> mylogfile.log
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to find a file which is older than 5 days but youger than 6 days? thomas2004ch Linux - Software 1 10-29-2013 04:30 AM
error msg while compiling kernel 'grubby fatal error no suitable templates found' suj Linux - Server 1 08-12-2010 10:33 PM
Using find and rm command to delete files over x days old 200mg Linux - Newbie 16 09-03-2008 07:41 PM
Deleting files after x days from the latest date file sriramsreedhars Programming 8 03-03-2007 10:30 AM
delete file more than 50 days christina_rules Linux - Newbie 6 05-24-2006 04:13 AM


All times are GMT -5. The time now is 04:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration