- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script to remove files each day
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
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
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
тАО02-28-2003 04:35 AM
тАО02-28-2003 04:35 AM
script to remove files each day
so they look like this TEST280203.REP
I intend to write a script to add to a contrab which will remove these for me.
at the moment I have to keep typing...
rm TEST280203.REP ABCD280203.REP DING280203.REP and so on!
can anyone suggest a solution please.
Thanks
bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 04:40 AM
тАО02-28-2003 04:40 AM
Re: script to remove files each day
A simple find command should probably do it. Something along these lines:
01 01 * * 01 /usr/bin/find /tmp -type f -name TEST* -mtime +10 -exec rm {} \;
You can modify the name parameter to suit your needs (like *.REP or whatever) and the mtime (last modifed time) may or may not be useful for you. And, of course, you should change the /tmp to the location you need.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 04:52 AM
тАО02-28-2003 04:52 AM
Re: script to remove files each day
if I didnt want to search all directories (i'm presuming thats what /usr/bin/find does)
what would you suggest.
I only want my script to point at one directory.
toptip about modifying the time
(im very new to all of this could you break down what each part does for me please)
thanks again
bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 04:53 AM
тАО02-28-2003 04:53 AM
Re: script to remove files each day
% cd yourdirectory
% ls | grep -E '^[A-Z]{4}[0-9]{6}\.REP' |xargs rm
the regular expression matches:
4 A-Z characters followed by:
6 numbers followed by:
.REP
or using classes:
% ls | grep -E '^[[:alpha:]]{4}[[:digit:]]{6}\.REP' |xargs rm
rgds, Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 05:04 AM
тАО02-28-2003 05:04 AM
Re: script to remove files each day
In the example I gave you, just change /tmp to the name of the directory you want to start in, like this:
find /home/bob -type f -name *.REP -exec rm {} \;
The "01 01 * * 01" is the syntax for crontab which says at 1 minute after 1AM, on any day of the month, in any month, on the first day of the week (Monday). The rest of it translates thusly: "/home/bob" is the starting point for the search. "-type f" says we're just looking for files. "-name *.REP" says the file needs to be named anything as long as the name ends in "REP". "-exec rm {} \;" says remove it.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 07:04 AM
тАО02-28-2003 07:04 AM
Re: script to remove files each day
Attached is a small script used to clean up our /tmp directory daily.
This can be modified for your purposes of rhe .REP files only.
Best regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 07:21 AM
тАО02-28-2003 07:21 AM
Re: script to remove files each day
I like your last option v much indeed and am going to use it
However I cannot use the *.REP part of it due to some files which I receive are required.
if I specify the front part of the filename would that work (like this)
find /tmp/bob -type f -name ABCD* FACE* HIDE* FOUR* GOLF* POLO* WORD* -exec rm {} \;
would the above remove files like the below
ABCD280203.REP
FACE280203.REP
HIDE280203.REP
FOUR280203.REP
GOLF280203.REP
or is this unlikely to work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 07:27 AM
тАО02-28-2003 07:27 AM
Re: script to remove files each day
find /tmp/bob -type f \( -name ABCD* -o -name ABCD* -o -name FACE* -o -name HIDE* -o -name FOUR* -o -name GOLF* -o -name POLO* -o -name WORD* \) -exec rm {} \;
That should do it! Test it by substituting an ls command in place of the rm:
find /tmp/bob -type f \( -name ABCD* -o -name ABCD* -o -name FACE* -o -name HIDE* -o -name FOUR* -o -name GOLF* -o -name POLO* -o -name WORD* \) -exec ls {} \;
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 08:03 AM
тАО02-28-2003 08:03 AM
Re: script to remove files each day
Ive tried that exact code below, where will the list appear???
10 16 * * * find /stage/intray -type f \( -name FUPD* -o -name TSFA* -o -name ESFA* -o -name FCOV* -o -name FCMV* -o -na
me FCGV* -o -name FCVV* \) -exec ls {} \;
thanks
bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 08:07 AM
тАО02-28-2003 08:07 AM
Re: script to remove files each day
For testing purposes, don't submit it to cron, just do the find from the command line. When you do use cron the output is emailed to the submitting user.
Pete
Pete