• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Schedule A Script to Delete files in directory path

I am a total novice when it comes to linux.  What I'd like to do is write a batch file to delete specific files in various directories & then schedule it to run periodically.  I've found documentation on how to delete entire directories but not the files contained within them.
0
ITApprendista
Asked:
ITApprendista
  • 2
1 Solution
 
omarfaridCommented:
to schedule you need to use crontab

please see:

http://www.adminschoice.com/docs/crontab.htm
http://www.linuxweblog.com/crotab-tutorial
http://www.tutorial5.com/content/view/95/51/
             
to delete content as well use

rm -r dirname
0
 
fosiul01Commented:
what about this

 find / -name filename  -exec /bin/rm -f '{}' +


so it will find the filename from Every directory in linux and will delete it

now just have to add this line crontab

let me know , if that command solved your purpose [ or i will have to tweak it more , as i am not that good in scripting!!!]
0
 
ITApprendistaAuthor Commented:
Well, I don't have specific filenames to delete, it's more a process of cleaning up the drive - ie, removing old log files from various directories periodically.  But don't necessarily want to remove the directories themselves, just all files within them
0
 
omarfaridCommented:
then try

find /path/to/dir -type f -exec rm {} \;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now