- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Removing files based on size, date etc.
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
07-14-2003 05:04 PM
07-14-2003 05:04 PM
I would like to create a script which takes parameters like - directory, size, days old etc. so that I can clear the files based on the above criteria. I would like to have the flexibility to modify the configuration files easily. Will appreciate for your comments on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 05:25 PM
07-14-2003 05:25 PM
Solutione.g.
# find /
Define the variables DIR, SIZE, TIME, NAME etc in a config file and source this config file from your script.
A note of caution: You need to test this throughly first to ensure you don't delete any important files. Use 'll' in place of 'rm' in the find command to see what files are found.
Also it's safer if possible to use wild card names to rm files.
Cheers
Con
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 05:30 PM
07-14-2003 05:30 PM
Re: Removing files based on size, date etc.
Date: Refer to 'atime' (* last accessed *)and 'mtime' (* last modified *) arguements in 'find' command.
-atime +7 (* greatet than 7 days *)
-atime 7 (* equal to 7 days *)
-atime -7 (* less than 7 days *)
find /dir -atime +7
Clear the files: Is that remove or zero out? That would be '-exec rm {} \;' to remove.
find /dir -atime +7 -exec rm {} \; (* remove all files greater than 7 days in /dir. *)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2003 05:58 PM
07-14-2003 05:58 PM
Re: Removing files based on size, date etc.
#Files/Directories --- Size --- Days
/home/user1 64
/home/user3 10
To explain this, I need to configure the size and days where applicable and then have the command pick-up the values as env. variables.
(Note - days is not specified for user1 whereas size is not specified for user3)
Hope this's not a complex task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2003 06:50 AM
07-16-2003 06:50 AM
Re: Removing files based on size, date etc.
like ex:
00 22 * * * /bin/find /home/user1 -size 1000 -atime -3 -exec rm {} \; > user1_rm.log
05 22 * * * /bin/find /home/user3 -size 300 -atime -7 -exec rm {} \; > user3_rm.log
I would first test this with -exec ls -l {} \; in crontab.
But then perhaps I did not understand your question fully ?
did it do the job for you ? then ... well glad I could be of help.
Jean-Pierre
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2003 06:58 AM
07-16-2003 06:58 AM
Re: Removing files based on size, date etc.
Create a function within a script that expects two arguments -- the name of the directory and the number of days after which unmodified files are purged. The script would look something like this:
#!/usr/bin/sh
function prune_directory
{
find $1 -mtime +$2 -type f -xdev|xargs -L 500 -i rm -f {}
}
#
prune_directory /home/user1 64
prune_directory /home/user3 10
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2003 06:47 PM
07-16-2003 06:47 PM
Re: Removing files based on size, date etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2003 07:59 AM
07-18-2003 07:59 AM
Re: Removing files based on size, date etc.
# find /var/tmp ???mtime 10 ???exec rm {} \; to remove files older than 10 days.
Removes under /tmp not been accessed more than 14days.
# find /tmp ???type f ???atime +14 ???exec rm {} \;
To remove a directory not been updated with files more then 14 days is :
# find /tmp ???type d ???atime +14 ???print ???exec rmdir {} \;
To remove a.out and *.o files
# find / -name ???a.out??? ???print > aout.list
# find / -name ???*.o??? ???print > o.list
To remove core files :
# find / -name ???core??? ???type f ???atime +14 ???exec rm {} \;
-Srini