LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-16-2009, 07:03 PM   #1
stefaandk
Member
 
Registered: Jun 2005
Distribution: Centos
Posts: 215

Rep: Reputation: 30
Question Remove files older then 30 mins of certain size with certain xtension?


How could I run a job that removes files from /tmp dir that have the following conditions:

older then 30 mins
gz or zip extension
larger then 1mb

This is on FreeBSD.

THanks
 
Old 03-16-2009, 07:14 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Use the find command in your job.
/usr/bin/find /tmp -type f -cmin +30 \( -iname "*.gz" -o iname "*.zip" \) -execdir rm '{}' \;

I'm not at my home computer & can't test it. I'm not absolutely certain about the -o part. I think that the filename tests need to be grouped so that the prior tests still hold. Otherwise, -iname "*.zip" will be enough for a match even if 100K or just 5 minutes old.

You may want to be careful with your script. Are you certain you aren't including some files that you don't want to delete. Maybe you want to include an owner test such as "-not -user root" to only delete temporary files by regular users.

Another potential problem is if a file is a zip or gz or bzip2 file but doesn't have an extension. A web browser may do that. In Linux, I might use the find command to locate large files older than 30 minutes, and pipe the output to "xargs -0 file". Does FreeBSD have the file command?

Last edited by jschiwal; 03-16-2009 at 07:17 PM.
 
Old 03-16-2009, 07:14 PM   #3
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
Either a Bash script using find or a Perl script using File::Find should do the job nicely. (If you're more comfortable with a different scripting language (Python, Ruby, whatever), that should work just fine too.)
 
Old 03-16-2009, 07:36 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Yup - "find" is your guy!

(Try doing *that* under Windows ;-))
 
Old 03-17-2009, 06:53 AM   #5
Biddle
Member
 
Registered: Jan 2009
Posts: 37

Rep: Reputation: 17
Quote:
Originally Posted by paulsm4 View Post
(Try doing *that* under Windows ;-))
Windows bashing becomes very tiresome and makes you no better than a windows zealot.
You do realise cygwin works under windows? and that windows has commands?

Last edited by Biddle; 03-17-2009 at 06:54 AM.
 
Old 03-17-2009, 03:33 PM   #6
charlitos
Member
 
Registered: Feb 2009
Posts: 51

Rep: Reputation: 16
the command -stat- might be helpful, check its man page.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to remove files older than 3 days rust8y Linux - General 26 10-04-2012 08:26 AM
how to recursively delete *.xtension files from a directory structure kpachopoulos Linux - General 6 08-24-2008 08:53 AM
remove grub and reinstall older bic Fedora 2 02-03-2008 06:55 AM
how to remove an older version of glib halamazoo Linux - Newbie 2 06-14-2004 10:42 AM
Correct way to remove older, unneeded kernels? wytiger Fedora 7 01-16-2004 09:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration