【引言】
大家知道,在写
shell
脚本时,经常会
crontab
定时删除一些文件,会经常用到
nd
命令
的
-mtime
参数,之前只是在用,没具体理解,今天集中时间学习下。
Linux
里 面 一 切 皆 文 件 , 想 了 解 文 件 状 态 时 间 , 就 得 熟 悉
nd
命 令 中 的
-atime,
-ctime
,
-mtime
这三个参数,其中
-mtime
用的更多。
使用命令
stat
先看下文件或者目录的信息:
!"# $
%&'())"*+)((,* !
-.)//01212134.35.3
6*1**7*89:8*98
-((22++;!(!+<!
='$((22+();+)/(<!
6*>((22+();+)/(<!
2
可以看到,关于时间信息有三个:最近访问时间
access time
(
2?@
)、最近更改时间
@'$?@
(
2@?@
)和 最近状态改动时间
*>?@
(
2?@
);但也看到了
创建
时间一项为空,说明
,*1
系统下是无法查看文件的创建时间的。
先看下
man nd
中的解释,大家直接看英文,这里不过多解释
-atime n
File was last accessed n*24 hours ago. When nd gures out how many 24-
hour periods ago the le was last accessed, any fractional part is ignored, so
to match -atime +1, a le has to have been accessed at least two days ago.
-ctime n
File's status was last changed n*24 hours ago. See the comments for -atime
to understand how rounding a&ects the interpretation of le status change
times.
-mtime n
File’
0 @7 *A( >; @@* ' 2?@ **
0
rounding a&ects the interpretation of le modication times.
解释
-atime, -ctime
和
-mtime
参数含义:
atime:
代表最近一次访问文件的时间,显示一个文件的内容或者运行一个
shell
脚本会
更新文件的
?@
。可用
2
命令查看。在
*(;;+
之前,文件系统默认会及时的更新
?@
;此后版本,只有发生以下三种情况之一才会更新
?@
。
;
将分区
mount
的挂载的时候指定采用非
?@
方式
(;
atime
小于
?@
或者小于
@?@
的时候
评论