LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 10-05-2007, 07:38 AM   #1
s0n|k
Member
 
Registered: Feb 2006
Distribution: RHEL4
Posts: 80

Rep: Reputation: 15
How to create a cron job to delete a folder's contents?


I need a way to erase the contents of a folder every so often.. Say, every 10 minutes. I would imagine that cron could help me do this, but I'm not sure how to go about writing a script that will accomplish this (similar to a bat file in Windows). Can someone give me a hand? I'm using RHEL4
 
Old 10-05-2007, 07:59 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
You will find most details on how to setup a cron job in
Code:
man 5 crontab
Briefly, you have to edit the crontab and add the time specification and the command to execute. First task
Code:
crontab -e
second add something like this
Code:
*/10 * * * * test -d /path/to/dir_to_clean && rm -rf /path/to/dir_to_clean/*
this will run the command line every 10 minutes of each hour and each day of the year, removing the content of dir_to_clean (if it exists). Please, when you are going to test an harmful command (indeed rm -rf is) double or triple check what you are typing. The risk is to delete something like your home dir or the whole system (if logged as root)

Last edited by colucix; 10-05-2007 at 08:00 AM.
 
  


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
Is it safe to delete the contents of /tmp? tramni1980 Slackware 19 01-15-2007 02:39 PM
How to create cron job to empty mbox folder/file sjmo2 Linux - General 4 03-23-2006 02:39 PM
delete mails thru cron job massoo Linux - General 0 01-12-2005 02:19 AM
cron job to delete files based on attributes alpha21 Linux - General 3 11-09-2004 12:06 PM
howto delete files via ftp from cron job ? cccc Linux - Networking 2 01-31-2004 06:49 PM


All times are GMT -5. The time now is 03:51 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