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

e.g.
-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
LVL 1
Mr-sarkAsked:
Who is Participating?
 
cjl7Connect With a Mentor freelance for hireCommented:
Hi,

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

Cheers

Jonas
0
 
laughingcoyoteCommented:
Are you running the script as root?
0
 
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)
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
danny_ebbersCommented:
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
0
 
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
0
 
danny_ebbersCommented:
yes they should

but NOTE

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

so

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.

0
 
TintinCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.