Найти старые файлы в каталоге

Я пишу скрипт ротации резервных копий, который предполагает взять все файлы старше 5 дней и удалить их. Проблема в том, что у меня странные результаты поиска. например:

[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

Итак, у нас есть файлы, которые определенно старше 5 дней. Но я не вижу файлов в «списке поиска»

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

Есть идеи?

0
задан 8 February 2017 в 14:53
1 ответ

Существуют различия между отметками времени в 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.

Итак, если вы используете ctime, вы будете искать файлы, в которых их данные или их владельцы / разрешения не изменялись с 5 дней.

Чтобы быть уверенным в датах ваших файлов, вы можете увидеть разные временные метки с помощью следующей команды:

# 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

Например, я меняю владельца fi.le сегодня, поэтому ctime сегодня и время mtime остается в 2016 году.

И после cat fi.le время доступа также обновляется:

# 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
1
ответ дан 4 December 2019 в 16:21

Теги

Похожие вопросы