linux下的文件都会被记录很多的时间参数,下面介绍主要的3种时间参数:
mtime(modification time ):当该文件的“内容数据”(文件的内容)被更改时,就会更新这个时间
ctime(status time):当文件的“状态”(例如权限,属性)被更改时,会更新这个时间
atime(access time):当文件的内容别使用(例如读取执行cat,more,less等操作),就会更新该时间
下面通过举例来说明:
[root@localhost 桌面]# who i am
root pts/0 2015-04-17 23:01 (:0.0)
[root@localhost 桌面]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
Release: 6.3
Codename: Final
[root@localhost 桌面]# man ls
Cannot open the message catalog "man" for locale "zh_CN.UTF-8"
(NLSPATH="/usr/share/locale/%l/LC_MESSAGES/%N")
Formatting page, please wait..
.........................
.........................
mtime(modification time ):当该文件的“内容数据”(文件的内容)被更改时,就会更新这个时间
ctime(status time):当文件的“状态”(例如权限,属性)被更改时,会更新这个时间
atime(access time):当文件的内容别使用(例如读取执行cat,more,less等操作),就会更新该时间
下面通过举例来说明:
[root@localhost 桌面]# who i am
root pts/0 2015-04-17 23:01 (:0.0)
[root@localhost 桌面]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.3 (Final)
Release: 6.3
Codename: Final
[root@localhost 桌面]# man ls
Cannot open the message catalog "man" for locale "zh_CN.UTF-8"
(NLSPATH="/usr/share/locale/%l/LC_MESSAGES/%N")
Formatting page, please wait..
.........................
.........................
--time=WORD
with -l, show time as WORD instead of modification time: atime
-u, access -u, use -u, ctime -c, or status -c; use specified
time as sort key if --sort=time
上面已经给了我们后面所带的参数:
-u,-c (也可以用ctime,atime) 不带参数默认就是mtime
上面我们可以知道ls显示出来的是mtime,也就是文件内容被更改的时间。
[root@localhost 桌面]# touch a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:14:13 CST
mtime:
[root@localhost 桌面]# vim a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:15:39 CST
[root@localhost 桌面]# ls -al a
-rw-r--r--. 1 root root 15 4月 17 23:15 a
ctime:
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:21:05 CST
[root@localhost 桌面]# chmod 700 a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:21:53 CST
with -l, show time as WORD instead of modification time: atime
-u, access -u, use -u, ctime -c, or status -c; use specified
time as sort key if --sort=time
.............................
.............................
上面已经给了我们后面所带的参数:
-u,-c (也可以用ctime,atime) 不带参数默认就是mtime
上面我们可以知道ls显示出来的是mtime,也就是文件内容被更改的时间。
[root@localhost 桌面]# touch a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:14:13 CST
mtime:
[root@localhost 桌面]# vim a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:15:39 CST
[root@localhost 桌面]# ls -al a
-rw-r--r--. 1 root root 15 4月 17 23:15 a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:21:05 CST
[root@localhost 桌面]# chmod 700 a
[root@localhost 桌面]# ls -al --time=ctime a
-rwx------. 1 root root 15 4月 17 23:21 a
atime:
-rwx------. 1 root root 15 4月 17 23:21 a
[root@localhost 桌面]# date
2015年 04月 17日 星期五 23:21:53 CST
[root@localhost 桌面]# cat a
hello,diy_os!
[root@localhost 桌面]# ls -al --time=atime a
-rwx------. 1 root root 15 4月 17 23:21 a
经常使用的是mtime,看重文件的内容什么时候被更改了,这个对于使用linux的用户很重要。
-rwx------. 1 root root 15 4月 17 23:21 a