您的位置:首页 > 其它

[转] stat命令输出结果中, Access,Modify,Change的含义

2015-08-31 10:59 489 查看
先建立一个空白文件a.txt

1
[emduser@emd tmp]$
touch
a.txt
2
3
[emduser@emd tmp]$
ls
-al a.txt
4
5
-rw-rw-r-- 1 emduser emd 0 Dec 14 16:44 a.txt
利用stat命令查看文件a.txt的各种属性

01
[emduser@emd tmp]$stat a.txt
02
03
File: `a.txt'
04
05
Size: 0 Blocks: 0IO Block: 4096 regular empty 
file
06
07
Device: fd00h/64768dInode: 654176Links: 1
08
09
Access: (0664/-rw-rw-r--)Uid: (501/ emduser) Gid: (506/ emd)
10
11
Access: 2011-12-14 16:44:23.000000000 +0800
12
13
Modify: 2011-12-14 16:44:23.000000000 +0800
14
15
Change: 2011-12-14 16:44:23.000000000 +0800
上述最后三行的含义如下:

Access : 文件最近一次被访问的时间

Modify:文件内容最近一次被修改的时间

Change: 文件属性最近一次被改变的时间

假如用cat命令将文件a.txt的内容输出到终端( 执行 cat a.txt), 那么只有a.txt的Access就被刷新了

假如我们把当前的时间追加到a.txt(执行 date >> a.txt) , 那么a.txt的Modify和Change都被刷新

假如我们把a.txt的权限改为777(执行 chmod 777 a.txt) , 那么只有a.txt的Change被刷新

假如我们用vi命令把文件a.txt打开, 然后保存退出,那么a.txt的Access,Modify和Change都被刷新

PS:我们可以使用命令touch更新a.txt的Access和Modify时间,比如:

touch -d 1999-01-01 a.txt // 将a.txt的Access和Modify时间改为1999-01-01
touch -a a.txt// 只将a.txt的Access时间改为当前系统时间
touch -m a.txt // 只将a.txt的Modify时间改为当前系统时间

当我们用ls -l a.txt看到的时间是Modify时间

PS: http://unix.stackexchange.com/questions/2464/timestamp-modification-time-and-created-time-of-a-file
There are 3 kind of "timestamps":

Access - the last time the file was read

Modify - the last time the file was modified (content has been modified)

Change - the last time meta data of the file was changed (e.g. permissions)

To display this information, you can use
stat
which is part of the coreutils.

stat
will show you also some more information like the device, inodes, links, etc.

Remember that this sort of information depends highly on the filesystem and mount options. For example if you mount a partition with the
noatime
option, no access information will be written.

A utility to change the timestamps would be
touch
. There are some arguments to decide which timestamp to change (e.g. -a for access time, -m for modification time, etc.) and to influence the parsing of a new given timestamp. See
man touch
for more details.

touch
can become handy in combination with
cp -u
("copy only when the SOURCE file is newer than the destination file or when the destination file is missing") or for the creation of empty marker files.

Thefieldst_atimeischangedbyfileaccesses,for example, by execve(2), mknod(2), pipe(2),
utime(2) and read(2) (of more than zero bytes).Other routines, like mmap(2), may or may notupdate
st_atime.

Thefield st_mtime is changed by file modifications, for example, by mknod(2), truncate(2), utime(2)
and write(2) (of more than zero bytes).Moreover, st_mtime of a directory is changed by the creation
ordeletionoffilesinthat directory.The st_mtime field is not changed for changes in owner,
group, hard link count, or mode.

The field st_ctime is changed by writing or by setting inode information (i.e.,owner,group,link
count, mode, etc.).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: