在目录中find旧文件

我正在编写备份轮换脚本,假设所有文件大于5天,并删除它们。 问题是我有一些奇怪的search结果。 例如:

[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]# 

有任何想法吗?

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,您将search5天以来没有修改其数据或其所有者/权限的文件。

为了确保你的文件的date,你可以用下面的命令看到不同的时间戳:

 # 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