LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-09-2004, 07:53 AM   #1
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Rep: Reputation: 0
cron job to delete files based on attributes


I am trying to basically makin a cron job which is to run hourly and perform the following:

In the the proposed directory, delete all *.ext files that are older than 24 hours...

I have to read man for 'find' I was advised, however, due to rush, I was wonderring if anyone would be kind enough to give me the solution or explain a summarized version of the process.
 
Old 11-09-2004, 07:57 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Create a small script like this to delete the files:


------------------------------------------------------------------------------
#!/bin/bash

find / -type f -iname *.ext -mtime +1 -exec rm {} \;


------------------------------------------------------------------------------

Make it executable with a chmod +x <scriptname>

And then just edit your crontab to set the time you want it to execute, days, etc and path to this script.
 
Old 11-09-2004, 08:02 AM   #3
alpha21
LQ Newbie
 
Registered: Nov 2004
Posts: 7

Original Poster
Rep: Reputation: 0
wow, that was fast,

thx... exactly what i was in search of, saves me reading the 10 page man

i believe the part that I wasn't familiar with was: -exec rm {} which I'm guessing basically executes a remove on the found items as it goes through the search, correct?
 
Old 11-09-2004, 12:06 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Yep, got that right :)
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Question - Delete files in a dir older than 48 hours? t3___ Linux - Newbie 5 10-11-2011 03:42 AM
Delete files based on date stefaandk Linux - General 3 06-17-2005 02:20 AM
delete mails thru cron job massoo Linux - General 0 01-12-2005 02:19 AM
Cron - Delete Files nigeledge Linux - Software 1 10-14-2004 10:36 PM
howto delete files via ftp from cron job ? cccc Linux - Networking 2 01-31-2004 06:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:54 AM.

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
Open Source Consulting | Domain Registration