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

Script isn't working with system time

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 stamp-h.in
-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
1 Solution
Are you running the script as root?
Mr-sarkAuthor Commented:
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)
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
Industry Leaders: 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!

Mr-sarkAuthor Commented:
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
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.


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...


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.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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