- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: problem with script to delete 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
11-14-2003 04:52 AM
11-14-2003 04:52 AM
find /usr/tmp -type f -atime +30 | cut -c 10- \
| grep -v -e / -e exp$ -e \' | xargs -i rm /usr/tmp/{}
If run as is (it's been commented out since this started) it takes out almost everything, lucky for me it didn't get anything anyone really cared about so I didn't have to go to tape!
If I take out the xargs at the end and just send it to a file it contains about half the files which include recent files.
So what it was doing before and not now was, removing any files that have not been accessed in the last 30 day excluding sub-directories.
I have no idea what changed but suddenly one day this line started removing the whole directory.
What could be wrong or what other way can I accomplish this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 05:24 AM
11-14-2003 05:24 AM
Re: problem with script to delete old files
If all you want to do is rm files unmodified in the last 30 days in a dir, then all you need is:
find /dir_name -mtime +30 -exec rm {} \;
You don't need to worry about dirs as rm will not delete them - rmdir is needed.
You could add a -i to the rm command to prompt for verification...
HTH,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 05:28 AM
11-14-2003 05:28 AM
Re: problem with script to delete old files
This little honey blows out core files older than 7 days
OLDEST=7
find / -type f -name core -mtime +${OLDEST} -print > ${RemoveList} 2>/dev/null
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 05:29 AM
11-14-2003 05:29 AM
Re: problem with script to delete old files
If I understand uou correct you want to remove all files in /usr/tmp older then 30 days but not remove files in subdirectorys.
I found no easy solution but perhaps "dirname" can be used. Something like:
find usr/tmp -type f -atime +30 |while read file
do
if [ `dirname $file` = "/usr/tmp" ]
then
rm $file
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 05:45 AM
11-14-2003 05:45 AM
Re: problem with script to delete old files
... | xargs -i ls -lu /usr/tmp/{} > mylisting.out
or something like that...
- John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 06:38 AM
11-14-2003 06:38 AM
Re: problem with script to delete old files
- John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 07:10 AM
11-14-2003 07:10 AM
Re: problem with script to delete old files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 07:26 AM
11-14-2003 07:26 AM
Re: problem with script to delete old files
Sorry I didn't see that you didn't want to walk the tree with this.
One thought that crosses my mind is to build a file with the find output & then grep -v the file to remove any entry with a "/" in it & use that file to input to an rm command.
Something like:
find /dir_name -mtime +30 -exec ls {} >> /tmp/rm_files \;
grep -v "/" /tmp/rm_files > /tmp/rm_files_rm
while read X
do
rm /tmp/dir_name/$X
done < /tmp/rm_files_rm
I haven't debugged this but have tried it - seems to work OK, so do it with a rm -i the first time to verify.
HTH,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 07:43 AM
11-14-2003 07:43 AM
Re: problem with script to delete old files
rm /dir_name/$X
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 08:58 AM
11-14-2003 08:58 AM
Re: problem with script to delete old files
but...
When sending the output to a file and looking at what it captures, it seems to grab too much (files created recently) so I wonder if I need to add a mtime also? I need to preserve files that are still being accessed otherwise they will need to run that report again which might be very inconvient.
I'm looking at the output of this and it might be what I need, don't know why -atime alone doesn't handle it anymore...
find /usr/tmp -type f -atime +30 -mtime +30| cut -c 10- \| grep -v -e / -e exp$ -e \'|xargs -i ll /usr/tmp/{}
I'll swap the ll for an rm and I should see a lot of new space available (hopfully not TOO much! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 09:11 AM
11-14-2003 09:11 AM
Re: problem with script to delete old files
atime is access - the find itself will modify atime. mtime is modification or change of the file contents. ctime is inode attribute change - owner, perms, links etc.
Just *what* are you looking for in these files in the above?
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 09:13 AM
11-14-2003 09:13 AM
Re: problem with script to delete old files
Also, following up on one of the other suggestions, I've also seen virus check s/w twiddle with atimes. So to reiterate that bit, if you've recently changed backup or virus check ( if any) s/w - those could be a cause of your backup script suddenly failing.
- John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 09:18 AM
11-14-2003 09:18 AM
Re: problem with script to delete old files
That last command using the rm did a good job
Doesn't look like find touchs the atime, you would need to open the file to touch it for the atime. I just ran about 20 finds on that directory today and came with the same results everytime
I'm not sure why filtering by atime +30 was giving files created 2 days ago (never been accessed so there was no atime to read?), but the addition of mtime +30 filtered out all of those giving me a list of what was mostly scratch files and forgotten user reports, perfect!
Not sure what was more helpful, all the feedback or me thinking 'outloud', anyway...thanks guys!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2003 09:24 AM
11-14-2003 09:24 AM
Re: problem with script to delete old files
# touch myfile
# ll myfile
-rw-r--r-- 1 root sys 0 Nov 14 14:23 myfile
# ls -lu myfile
-rw-r--r-- 1 root sys 0 Nov 14 14:23 myfile
# touch -a -t 10010000 myfile
# ll myfile
-rw-r--r-- 1 root sys 0 Nov 14 14:23 myfile
# ls -lu myfile
-rw-r--r-- 1 root sys 0 Oct 1 00:00 myfile
#
- John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2003 01:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2003 03:12 PM
11-16-2003 03:12 PM
Re: problem with script to delete old files
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2003 09:59 PM
11-16-2003 09:59 PM
Re: problem with script to delete old files
are you still with us? If so, is your problem solved?
greetings,
Michael.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2004 01:54 AM
02-11-2004 01:54 AM
Re: problem with script to delete old files
find /usr/tmp -type f -atime +30 -mtime +30 | cut -c 10- | grep -v -e / -e exp$ -e \' | xargs -i rm /usr/tmp/{}
Thanks again for all the help!