- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: "rm -r `" help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2008 11:43 AM
тАО04-22-2008 11:43 AM
I have a cron job running to clean logs old
than 3 days. There is always some error msg
in the log. How to get rid of it?
# /usr/bin/find $FPATH -mtime +3 -exec rm -r {} \; >> /tmp/clean_log 2>&1
Example msg in /tmp/clean_log:
/usr/bin/find: /my-path/xyz: no such file or directory.
The xyz directory already got removed even before removing the files in xyz. Then "rm -r"
try to remove it again?
Thanks in advance,
IDT
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2008 11:58 AM
тАО04-22-2008 11:58 AM
SolutionYou really want to descend the directory and deal with its contents first. Hence:
# /usr/bin/find $FPATH -depth -mtime +3 -exec rm -r {} \+ >> /tmp/clean_log 2>&1
Notice the addition of '-depth'. Notice, too, that I changed the semicolon (;) to a plus (+) character. This causes find to buffer many arguments together and '-exec' the process passing them as a block. This avoids spawning one process per file found, greatly improving performance.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2008 12:28 PM
тАО04-22-2008 12:28 PM
Re: "rm -r `" help
It almost work but it complains:
find: missing argument to '-exec'
IDT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2008 12:36 PM
тАО04-22-2008 12:36 PM
Re: "rm -r `" help
write a twoliner "/tmp/myrm"
#!/usr/bin/sh
rm -r "$@"
and after
chmod +x /tmp/myrm
use
find $FPATH -depth -mtime +3 -exec /tmp/myrm {} \+ >> /tmp/clean_log 2>&1
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2008 12:37 PM
тАО04-22-2008 12:37 PM
Re: "rm -r `" help
> It almost work but it complains:
find: missing argument to '-exec'
Then, I suspect that you are running a release much earlier than 11.11 or not an HP-UX. In this case, go back to the use of the semicolon in lieu of the "+", or pipe the 'find' output to 'xargs' to do the buffering.
By the way, since you are recursively removing files and directories, you could also do:
... rm -rf ...
...which has the property of suppressing non-existent file messages.
Beware, that by not specifying FILES (with '-type f') you may be taking DIRECTORIES and the FILES therein that you DON'T want! That is because any file that is removed from a directory causes the 'mtime' of the *directory* to be updated.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-22-2008 01:07 PM
тАО04-22-2008 01:07 PM