Script isn't working with system time

Posted on 2005-04-08
Last Modified: 2010-04-20
A few days ago we discussed here a script to delete files dat are older then an X day.
After doing this we got this script:

cd /admin/downloads/php-5.0.4
find . -ctime +1 -exec rm -rf {} \;
cd -

it was working fine untill today ( isn't working on my redhat machine, is working on my debian machien :S)
When i take a look in the folder /admin/downloads/php-5.0.4 i can see that most files are older then the machine date

-rwxr-xr-x   1 root root     108 Dec 30  1999 snapshot
-rw-r--r--   1 root root      10 Nov 21  1999
-rw-r--r--   1 root root       1 Dec  1  2000 stub.c
drwxr-xr-x   9 root root    4096 Apr  3 11:42 tests
-rw-r--r--   1 root root    5924 May 28  2004 TODO
-rw-r--r--   1 root root     723 May 28  2004 TODO-5.1
-rw-r--r--   1 root root     129 Mar  7  2002 TODO.BUILDv5
-rw-r--r--   1 root root    4789 May 28  2004 TODO-PHP5
drwxr-xr-x   2 root root    4096 Apr  6 11:52 TSRM
drwxr-xr-x   4 root root    4096 Apr  3 11:42 win32
drwxr-xr-x   4 root root   12288 Apr  6 11:52 Zend

But when i execute the script nothing happens and the files are still there ( ps i untarred php5.0.4 3 days ago but some dates are way older :S )

what is wrong ? thnx in advance
Question by:Mr-sark
    LVL 1

    Expert Comment

    Are you running the script as root?
    LVL 1

    Author Comment

    yes i am

    the directory php-5.0.4 is also chmod 777 and owner of root:root
    ( i know this is insecurte but it's only for testing)
    LVL 4

    Expert Comment

    Oke looks like a strange situation in first view, but probably some really sense makeing explanation there

    first analyze if the find command works
    find -ctime +1

    if you get all the files you should delete. its not the find script that fails
    if it fails then might be something wrong with permissions.

    then try to manually delete the file
    rm -f <filename>

    see if it successfully works out.
    ifso then it's oke, if not then it's a

    if Permission error (fixable with chmod / chown)
    if Operation not permitted (then file might be in use, or blocked with inmutable flag(fixable with chattr)

    please report your results in here
    LVL 1

    Author Comment

    thnx for the response.
    To get things straight: the scripts looks for files in a path that are older then 1 day ( if i change +1 into +4 it checks older then 4 days rigth ?)

    When i use the command:

    find -ctime +1
    it shows me a way to long list.

    find -ctime +4 3 2
    if i use one of these it shows me nothing while there are files that are older then 2 days

    The rm -f function is working well
    LVL 4

    Expert Comment

    yes they should

    but NOTE

    the comparison of ctime is based on timestamps not on nr of days


    so sysdate = 1-1-2005 01:00
       file date = 2-1-2005 00:58

    Might be considered as 0 or 1 days
    i am not sure.

    but anyway first make sure if you're find command selects the right files you want.

    LVL 14

    Accepted Solution


    The problem is that find looks at 'changed time', do a 'stat filename' and you'll see what the problem is...

    What you could do is use the -mtime instead?! Given that your files aren't modified...


    LVL 48

    Expert Comment

    You are much better off using

    find /admin/downloads/php-5.0.4 -mtime +1 -exec rm -f {} \;

    Many things can change the ctime on a file, like a chmod, chown, etc.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
    Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
    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…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now