Schedule A Script to Delete files in directory path

Posted on 2009-04-16
Last Modified: 2013-12-16
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.
Question by:ITApprendista
    LVL 40

    Expert Comment

    to schedule you need to use crontab

    please see:
    to delete content as well use

    rm -r dirname
    LVL 29

    Expert Comment

    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!!!]

    Author Comment

    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
    LVL 40

    Accepted Solution

    then try

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now