- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script to delete outdated 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
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
тАО09-18-2003 06:07 AM
тАО09-18-2003 06:07 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 06:11 AM
тАО09-18-2003 06:11 AM
Re: Script to delete outdated files
cd
find . -mtime +7 -exec rm {} \;
This will delete all files in this dir older than 7 days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 06:14 AM
тАО09-18-2003 06:14 AM
Re: Script to delete outdated files
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 06:19 AM
тАО09-18-2003 06:19 AM
Re: Script to delete outdated files
To do the find nonrecursively add
! -depth
So Stefan's command would be
find . ! -depth -mtime +7 -exec rm -i {} \;
Note I added the -i to rm to have it query you just in case you find files you wish to retain.
If it's a long list & you don't want answer Y/N to them all then just replace rm with ll to get a listing & remove the -i
HTH,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 06:21 AM
тАО09-18-2003 06:21 AM
Re: Script to delete outdated files
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 06:57 AM
тАО09-18-2003 06:57 AM
Re: Script to delete outdated files
Sorry, for my silly question but English isn't my native tongue.
If so then I doubt that the suggested "! -depth" will work.
Instead you should use find's -prune switch.
But I guess fiddling together an appropiate -prune logic will be more cumbersome than putting together a few lines of Perl (or even C if you prefer) that simply use the syscalls opendir() and readdir().
If you don't want to engulf submounts in the find you'd have to use the -xdev switch.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 07:06 AM
тАО09-18-2003 07:06 AM
Re: Script to delete outdated files
Good catch Ralph.
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 07:33 AM
тАО09-18-2003 07:33 AM
Re: Script to delete outdated files
If cd to /dumpdat1 and do
find . -depth -mtime +3
I get as output several lines with file names in /dumpdat1, but if I do
find . ! -depth -mtime +3
all my output disappears.
Ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 07:38 AM
тАО09-18-2003 07:38 AM
Re: Script to delete outdated files
find . ! -prune -mtime +3
Either gives me no output.
Ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 07:47 AM
тАО09-18-2003 07:47 AM
Re: Script to delete outdated files
try
find . -mtime +7 -print |while read a
do
if [ $(dirname $a) = "." ]
then
rm $a
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 07:55 AM
тАО09-18-2003 07:55 AM
Solutionfind . \( -type d ! -name . -prune \) -o \( -type f -mtime +7 ! -name "." -print \) -exec rm {} \;
Try it, works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:34 AM
тАО09-18-2003 08:34 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:34 AM
тАО09-18-2003 08:34 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:34 AM
тАО09-18-2003 08:34 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:35 AM
тАО09-18-2003 08:35 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:35 AM
тАО09-18-2003 08:35 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:35 AM
тАО09-18-2003 08:35 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:35 AM
тАО09-18-2003 08:35 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:35 AM
тАО09-18-2003 08:35 AM
Re: Script to delete outdated files
Your syntax is wrong... mtime should come first. refer to the man page also for full syntax
YES:
find . -mtime +3 -prune
NO:
find . -prune -mtime +3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:40 AM
тАО09-18-2003 08:40 AM
Re: Script to delete outdated files
The usage of -prune switches soon becomes quite nasty, especially when you have to quote all those parantheses to protect from the shell.
That's why I'd prefer something Perlish like
e.g.
opendir DH, '/tmp' or die "opendir failed: $!\n";
@files = grep {! -d "/var/$_"} grep !/^[.]{1,2}$/, readdir DH;
Now if you're a hot shot you could do something like
unlink map("/tmp/$_", @files);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 08:42 AM
тАО09-18-2003 08:42 AM
Re: Script to delete outdated files
But this should be easy to insert in the grep() call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2003 09:26 AM
тАО09-18-2003 09:26 AM
Re: Script to delete outdated files
find . \( -type d ! -name . -prune \) -o \( -type f -mtime +7 ! -name ".*" -print \) -exec rm {} \;
Sorry, I don't know Perl, but I heard she's a blast.