0

I'm writing backup rotation script, that suppose to take all files older then 5 days and delete them. Problem is that i've got some weird search results. for example:

[root@spr1-nas01 storage]# date
Wed Feb  8 14:48:09 EET 2017
[root@spr1-nas01 storage]# ll
-rwxr-xr-x. 1 root root  1366884352 Dec 24 02:31 BACKUP_20161224
-rwxr-xr-x. 1 root root    51986944 Jan 28 19:37 BACKUP_20170128
-rwxr-xr-x. 1 root root  9681633280 Jan 31 06:45 BACKUP_20170131

So we got some files that definitely older then 5 days from now. But i dont see any files in 'find listing'

[root@spr1-nas01 storage]# find . -ctime  +5 -ls
[root@spr1-nas01 storage]#

Any ideas?

Jaels
  • 67
  • 1
  • 10

1 Answers1

1

There are differences between the timestamps in UNIX :

Three times tracked for each file in Unix are these:

    access time – atime
    change time – ctime
    modify time – mtime

atime – File Access Time

Access time shows the last time the data from a file was accessed – read by one of the Unix processes directly or through commands and scripts.
ctime – File Change Time

ctime also changes when you change file's ownership or access permissions. It will also naturally highlight the last time file had its contents updated.
mtime – File Modify Time

Last modification time shows time of the  last change to file's contents. It does not change with owner or permission changes, and is therefore used for tracking the actual changes to data of the file itself.

So if you use ctime you will search the files where theirs datas or their owners/permissions has not been modified since 5 days.

To be sure of the dates of yours files, you can see the differents timestamps with the following command :

# stat fi.le

 Access : 2016-11-14 11:36:21.850314996 +0100
Modif. : 2016-11-10 14:20:25.378246071 +0100
Changt : 2017-02-08 15:00:57.464000000 +0100

For example, I change the owner of fi.le today, so the ctime is today and the mtime is stayed in 2016.

And after cat fi.le, the access time is also updated :

# cat fi.le
# stat fi.le

Accès : 2017-02-08 15:03:09.400000000 +0100
Modif. : 2016-11-10 14:20:25.378246071 +0100
Changt : 2017-02-08 15:00:57.464000000 +0100
Sorcha
  • 1,315
  • 8
  • 11