Simple Linux script question about deleteing files after x days

Posted on 2005-04-08
Last Modified: 2010-04-17

I know my around Linux but i'm a novice when it comes to shell scritping.

I want to add a few lines to a script that will find all files older than x days and delete them,
it must start at a directory i specifiy and work on all subdirectories below.
Some of the filenames may contain spaces and mixed case letters etc.
I don't want to use perl or anything other than standard shell script commands.

Its a script to run on an FTP server that our mobile staff use for transferring stuff to and from the office.  In the office the FTP server is just a windows share and so people tend to use windows filenames - hence the spaces etc.  Of course they just wont keep the area tidy so i want to add a script that will remove everything older than 4 or 5 days.

The FTP server is running under Fedora Core 3.



Question by:simonenticott
    LVL 4

    Expert Comment

    find . -ctime +$1 -exec rm -rf {} \;

    for testing you should first use this

    find . -ctime +$1 -exec echo Marked for deletion: {} \;

    LVL 4

    Accepted Solution

    find $1 -ctime +$2 -exec rm -rf {} \;

    for testing you should first use this:

    find $1 -ctime +$2 -exec echo Marked for deletion {} \;

    write the 2 lines in a plain text file

    chmod 755 filename

    then you can use:
    ./yourfilename <path> <nr of days old>

    LVL 5

    Author Comment

    Thanks danny, i've spent ages trying to figure this out !


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    ImportError: No module named 'pypyodbc' - python 3.5.2 3 250
    java constructor error 8 65
    changeXy challenge 13 40
    array11 challenge 16 40
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    734 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

    19 Experts available now in Live!

    Get 1:1 Help Now