LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   find and delete old files (https://www.linuxquestions.org/questions/linux-general-1/find-and-delete-old-files-798017/)

RAFAL 03-26-2010 05:58 AM

find and delete old files
 
Hi

I would like to delete some old redolog file in oracle directory and try this command:
Code:

find /oracle/IDS/oraarch -ctime +1 -print
Just to see a list (print, which I want to replace with delete)
I tried as well mtime and atime.
Unfortunately I get listed only 3 files (first 3 files), but the list should be much longer. I though maybe system time is wrong, but command 'date' gives me correct time. When I execute 'ls -la' I see whole list of files with dates.
I also tried to use 'stat <FILE>' to check some single files.
When I use:
Code:

find /oracle/IDS/oraarch -ctime 1 -print
the list is longer, but in this case I do not see older files

has anybody explanation for this strange behavior?

regards
Rafal

blacky_5251 03-26-2010 03:05 PM

The time options of find are atime, ctime and mtime. These refer to, in order, the time the file was last accessed, the time the file's status was last changed, and the time the files data was last modified.

The option that most closely relates to the output of ls is mtime, so change your find statement to use that instead of ctime.

RAFAL 03-29-2010 04:55 AM

Quote:

Originally Posted by blacky_5251 (Post 3913660)
The time options of find are atime, ctime and mtime. These refer to, in order, the time the file was last accessed, the time the file's status was last changed, and the time the files data was last modified.

The option that most closely relates to the output of ls is mtime, so change your find statement to use that instead of ctime.

hi

Thanks for the answer, but as I said "I tried as well mtime and atime."
its all the same, to I really do not know what is the issue here. Apparently something with "+" sign and the way how its interpreted

regards
Rafal

blacky_5251 03-29-2010 05:57 AM

Sorry for not reading properly. The difference between 1 and +1 is "exactly 1" compared to "more than 1" days ago. If you specify the "+" in your find, then it means "more than that many days" ago. If you leave it out, it means "exactly that many days ago".

An example from my server, using 32 instead of 1:-
Code:

[root@eddie WORK]# find . -mtime 32 -exec ls -ld {} \;
drwxrwsr-x 2 mhb crms 4096 Feb 25 17:43 ./at10528WRK
drwxrwsr-x 2 mhb crms 4096 Feb 25 17:45 ./at10735WRK
drwxrwsr-x 2 mhb crms 4096 Feb 25 17:43 ./at10573WRK
drwxrwsrwx 2 irb crms 4096 Feb 25 15:18 ./at1284WRK
drwxrwsr-x 2 mhb crms 4096 Feb 25 12:12 ./at21545WRK
drwxrwsrwx 2 irb crms 4096 Feb 25 15:20 ./at1902WRK
drwxrwsrwx 2 irb crms 4096 Feb 25 15:20 ./at1743WRK
drwxrwsrwx 2 irb crms 4096 Feb 25 15:20 ./at1856WRK
drwxrwsr-x 2 mhb crms 4096 Feb 25 17:30 ./at21605WRK
[root@eddie WORK]# find . -mtime +32 -exec ls -ld {} \;|grep "Feb 25"
[root@eddie WORK]#

Using "32" returns entries that are that many days old exactly, but using "+32" (and grepping only for Feb 25 to exclude all the other files it would return) doesn't return the same entries from Feb 25.

Plus, I still think you should use mtime instead of ctime ;)

RAFAL 03-30-2010 03:59 AM

Quote:

Originally Posted by blacky_5251 (Post 3916544)
find . -mtime +32 -exec ls -ld {} \;|grep "Feb 25"

I tried again and now worked fine.
Thanks a lot for your help
I don't understand why it didn't worked before, but the main thing is : it works now

regards
Rafal


All times are GMT -5. The time now is 06:25 AM.