LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron Question - Delete files in a dir older than 48 hours? (http://www.linuxquestions.org/questions/linux-newbie-8/cron-question-delete-files-in-a-dir-older-than-48-hours-132542/)

t3___ 01-07-2004 06:21 PM

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

g-rod 01-07-2004 06:49 PM

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.

t3___ 01-09-2004 11:42 AM

excellent!!! Thank you so much for you help!

apsrbs 10-10-2011 04:49 AM

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?

chrism01 10-10-2011 03:33 PM

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 ...

apsrbs 10-11-2011 03:42 AM

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


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