LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-07-2004, 06:21 PM   #1
t3___
Member
 
Registered: Sep 2003
Posts: 240

Rep: Reputation: 30
Cron Question - Delete files in a dir older than 48 hours?


Background: I am setting up a temporary directory on my network (linux samba svr) that will allow users to temorarily store files, facilitate put/get file exchanges between users, create test files/dir temorarily, etc. Users are only allowed to store files there for a very limited amount of time.

Objective: I would like to create a cronjob or script file that automatically deletes file 48 hours after they are copied to the folder (or delete files that are older than 48 hours).

Cron? Pearl Script?

Im a newbie - please help!

Thanks
 
Old 01-07-2004, 06:49 PM   #2
g-rod
Member
 
Registered: Dec 2003
Location: Long Island, NY USA
Distribution: RedHat, SUSE
Posts: 336

Rep: Reputation: 30
I would use cron and find.

#!/bin/sh
find <startdir> -ctime 48 -exec rm -f {} \;

where <startdir> is the full path to the direcotry where the temp file is stored.
put the above in /etc/cron.hourly/remove_48.sh
You might want to change rm -f to ls -l to make sure it is going to remove the correct files first as a test.
 
Old 01-09-2004, 11:42 AM   #3
t3___
Member
 
Registered: Sep 2003
Posts: 240

Original Poster
Rep: Reputation: 30
excellent!!! Thank you so much for you help!
 
Old 10-10-2011, 04:49 AM   #4
apsrbs
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
Hi, thanks for this script. I'm trying to apply it in my environment, which is Red Hat, but I'm getting the following error message:
fin: missing argument to '-exec'
I had to remove the #!/bin/sh for some reason, it was coming up as a bad interpreter. Unfortunately, I am a total novice on Linux, and I didn't set this environment up, so I don't know if there are some restrictions on what scripting language I can use or anything.

Can anyone offer any assistance?
 
Old 10-10-2011, 03:33 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,287

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Please show the exact script and check that the start dir you specified is correctly named; note that Linux is case sensitive(!) for cmds, files and parameters/switches ...
 
Old 10-11-2011, 03:42 AM   #6
apsrbs
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
Thanks for the response, the script I used is:
find /Invoice -ctime 48 -exec rm -f {} \;
 
  


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
delete files older then a month? Red Squirrel Linux - Software 1 10-05-2005 10:54 PM
Delete files after 24 hours Azhrarn Linux - Newbie 3 08-29-2005 12:00 PM
Deleting Files Older Than 2 Hours using Find? LinuxGeek Linux - Software 1 06-29-2005 06:10 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 02:40 PM
delete files in server that is older than 30 days using cronjob latheesan *BSD 2 06-14-2005 12:37 PM


All times are GMT -5. The time now is 02:09 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration