cron job for deleting files older than 1 week

ice ice.simx at gmail.com
Fri Mar 9 13:18:19 UTC 2007


better write all commands in a separate script file and use absolute path.
Otherwise cron will be failed to run the script.

to make entry in crontab]$ crontab -e
press 'i' to switch to insert mode
and write

25 13 * * * /path/myscript.sh

press 'wq' to save and quit. This script will run everyday at 01:25 PM
make sure to give executabel permission to ur script


On 3/9/07, Gabriel Dragffy <dragffy at yandex.ru> wrote:
>
> Matthew Flaschen wrote:
> > Carsten Aulbert wrote:
> >> Gabriel Dragffy wrote:
> >>
> >>> Could some one provide me with a sample script that I could run as a
> >>> cron job and it would go through the streamripper folder deleting
> files
> >>> older than 1 week (for example). Many thanks.
> >>> gabe
> >>
> >> Again, use with care ;)
> >>
> >> find /path -name "stream*.mp3" -mtime +6 | xargs -i rm -f {}
> >>
> >> That should delete all files named "stream*.mp3" found in the directory
> >> hierarchie /path with modification date older than 6 days.
> >>
> >> For mor info, please read the man page of find, xargs and rm and try
> the
> >> stuff first with 'echo' instead of rm to make sure you don't delete
> >> anything you don't want to delete.
> >
> > Why do you use xargs?  find is designed to do the same thing with just
> > -delete:
> >
> > find -name "stream*.mp3" -mtime +6 -delete
> >
> > In general, you could just do:
> >
> > find -name "stream*.mp3" -mtime +6 -execdir rm '{}' '+'
> >
> > Also, the '+' means it uses the same command line for multiple files,
> > which is more efficient.
> >
> > For testing:
> >
> > find -name "stream*.mp3" -mtime +6 -print
> >
> > No need to read two man pages. :)
> >
> > Matt Flaschen
> >
>
> Cheers Matt,
> How would that look inside a cron tab? Or would it have to go in to a
> seperate script?
>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>



-- 
Sagittarius

"Darkness of this UNIVERSE has many secrets."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20070309/072bc878/attachment.html>


More information about the ubuntu-users mailing list