- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh script for removing old files
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
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
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
06-06-2003 12:39 PM
06-06-2003 12:39 PM
Thanks,
Dave
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 12:47 PM
06-06-2003 12:47 PM
Solutionfind /your/dir -type f -mtime +60 -exec rm {} \;
Be very carefull with find and "-exec rm" make sure that you use an EXPLICIT file location. NEVER cd to directory and start removing files in a script. That will bite you someday when the directory is moved/renamed etc.
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 12:50 PM
06-06-2003 12:50 PM
Re: ksh script for removing old files
find /tmp/ -type f -mtime -1 > $FILE_LIST_TMP 2>$RESULTS_FILE
==> used to build a list of files created in the last 24 hours. Then using this list simply do a for loop on a cat of the file to perform the rm on.
Man find, you will find other time options. In this case -1 is the interval of 24 hour periods.
Best of luck.
Regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 12:52 PM
06-06-2003 12:52 PM
Re: ksh script for removing old files
find dirname -type f -mtime +60 -exec rm {} \;
substitute something innocuous like "echo" for the rm until you feel safe. This will delete all regular files older than 60 days undir dirname (and it's subdirectories).
The date +%j stuff is not very robust because of end of year issues.
If you must you something that converts Date encoded filenames into meaningful numeric values then I would use caljd.sh. It will easily parse the Monthnames (in any language). Search the forums for caljd.sh and you should get a number of hits. Get version 2.1; it's the latest
.
If you will give a few exact examples of the filenames, I can probably write an example caljd.sh call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 01:01 PM
06-06-2003 01:01 PM
Re: ksh script for removing old files
#!/bin/sh
# Script to remove old print jobs
# Geoff Wild
# April 4 2002
#
find /var/spool/lp/receive -name '*III' -mtime +7 -exec rm {} \; >/tmp/lp.receive.log
find /var/spool/lp/receive -name '*AAA' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log
find /var/spool/lp/receive -name '*EEE' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log
find /var/adm/lp/XEB -name '*ftplog' -mtime +7 -exec rm {} \; >>/tmp/lp.receive.log
RGds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 01:10 PM
06-06-2003 01:10 PM
Re: ksh script for removing old files
All good and viable examples. I thank you for the assistance. For the life of me I can't see how but I missed the -exec!!!!
Clay,
Thanks for the info on the caljd.sh. I'll look into it and post if I can't figure out how to utilize it. The information provided is quite sufficient for now.
Thanks again,
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2003 01:38 PM
06-06-2003 01:38 PM
Re: ksh script for removing old files
More efficient than
find /path -type f -exec rm {} \;
is
find /path -type f -exec rm \+
which works just like
find /path -type f | xargs rm
As far as I know, this is only true with HP-UX find. For portability, use the find|xargs pipeline when working with long lists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2003 12:13 PM
06-09-2003 12:13 PM
Re: ksh script for removing old files
Thanks for the additional information.
Dave