- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: find -exec rm question
Operating System - HP-UX
1819905
Members
2878
Online
109607
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
тАО11-17-2010 12:57 PM
тАО11-17-2010 12:57 PM
find -exec rm question
I'm running a nightly cleanup script to clear files from a specific directory. The script works as expected, however, now I have a sub-directory which is also being cleared. This is the command I'm using
find /sb/SB.EXC/data/EDI/alltests -type f -mtime +1 -exec rm {} \;
What I want is to clear files in the ...alltest directory without affecting files in the ...alltest/AFEN directory. Any help with amending or creating a new command line is greatly appreciated.
find /sb/SB.EXC/data/EDI/alltests -type f -mtime +1 -exec rm {} \;
What I want is to clear files in the ...alltest directory without affecting files in the ...alltest/AFEN directory. Any help with amending or creating a new command line is greatly appreciated.
- Tags:
- find
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 01:40 PM
тАО11-17-2010 01:40 PM
Re: find -exec rm question
I think if you add the -prune option, you'll get what you want.
--
Jeff Traigle
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-17-2010 02:31 PM
тАО11-17-2010 02:31 PM
Re: find -exec rm question
Hi :
# cd /sb/SB.EXC/data/EDI/alltests && find . ! -path "./AFEN*" -type f -mtime +1 -exec rm {} +
Notice that we terminate the '-exec rm {}' with a "+". This greatly improves performance by spawning a 'rm' command with multiple arguments. For 'find' this variation of the '-exec' option acts as if you had used 'xargs' to bundle up many arguments for execution.
Regards!
...JRF...
# cd /sb/SB.EXC/data/EDI/alltests && find . ! -path "./AFEN*" -type f -mtime +1 -exec rm {} +
Notice that we terminate the '-exec rm {}' with a "+". This greatly improves performance by spawning a 'rm' command with multiple arguments. For 'find' this variation of the '-exec' option acts as if you had used 'xargs' to bundle up many arguments for execution.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-18-2010 12:01 AM
тАО11-18-2010 12:01 AM
Re: find -exec rm question
>Jeff: I think if you add the -prune option, you'll get what you want.
Since -prune is very complicated and rm is dangerous, here is what should work:
find /sb/SB.EXC/data/EDI/alltests -name AFEN -prune -o -type f -mtime +1 -exec echo rm {} +
Remove the "echo" when you are satisfied it does what you want.
>JRF: ! -path "./AFEN*"
-prune is faster than a -path compare for the zillions of files in AFEN.
>For 'find' this variation of the '-exec' option acts as if you had used 'xargs' to bundle up many arguments for execution.
This may be faster than xargs since find(1) packs the arg list full (Mb) but xargs is very limited (~2000?).
Since -prune is very complicated and rm is dangerous, here is what should work:
find /sb/SB.EXC/data/EDI/alltests -name AFEN -prune -o -type f -mtime +1 -exec echo rm {} +
Remove the "echo" when you are satisfied it does what you want.
>JRF: ! -path "./AFEN*"
-prune is faster than a -path compare for the zillions of files in AFEN.
>For 'find' this variation of the '-exec' option acts as if you had used 'xargs' to bundle up many arguments for execution.
This may be faster than xargs since find(1) packs the arg list full (Mb) but xargs is very limited (~2000?).
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP