atime/mtime/ctimeを確認してみる

CentOS6上で、atime,mtime,ctimeを確認してみる。


ファイルを作成する

$ touch sample.txt

statコマンドでatime,mtime,ctimeを確認できる。

$ stat sample.txt
  File: `sample.txt'
  Size: 0               Blocks: 0          IO Block: 4096   通常の空ファイル
Device: fd02h/64770d    Inode: 3407879     Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  500/     dev)   Gid: (  500/     dev)
Access: 2015-02-11 11:21:26.716563337 +0900
Modify: 2015-02-11 11:21:26.716563337 +0900
Change: 2015-02-11 11:21:26.716563337 +0900

参照するとatimeが変わる。

$ cat sample.txt
$ stat sample.txt
・・・
Access: 2015-02-11 11:22:24.123554905 +0900
Modify: 2015-02-11 11:21:26.716563337 +0900
Change: 2015-02-11 11:21:26.716563337 +0900

変更するとmtime,ctimeが変わる

$ echo XXX >> sample.txt
$ stat sample.txt
・・・
Access: 2015-02-11 11:22:24.123554905 +0900
Modify: 2015-02-11 11:23:11.947565076 +0900
Change: 2015-02-11 11:23:11.947565076 +0900

属性を変えた場合はctimeだけが変わる。

$ chmod 777 sample.txt
$ stat sample.txt
・・・
Access: 2015-02-11 11:22:24.123554905 +0900
Modify: 2015-02-11 11:23:11.947565076 +0900
Change: 2015-02-11 11:24:05.443517789 +0900

「-lu」でatime、「-l」でmtime、「-lc」でctimeを確認できる。

$ ls -lu
-rwxrwxrwx 1 hoge hoge 4  211 11:22 2015 sample.txt
$ ls -l
-rwxrwxrwx 1 hoge hoge 4  211 11:23 2015 sample.txt
$ ls -lc
-rwxrwxrwx 1 hoge hoge 4  211 11:24 2015 sample.txt

touchコマンドでatimeとmtimeは変更できる。

$ touch -a -d "2000/1/1 00:00:00" sample.txt
$ touch -m -d "2000/2/2 00:00:00" sample.txt
$ stat sample.txt
・・・
Access: 2000-01-01 00:00:00.000000000 +0900
Modify: 2000-02-02 00:00:00.000000000 +0900
Change: 2015-02-11 11:26:15.098565489 +0900

補足

mvでファイル名を変更した場合は、ctimeだけ変わる。

$ mv sample.txt sample_mv.txt
$ stat sample_mv.txt
・・・
Access: 2000-01-01 00:00:00.000000000 +0900
Modify: 2000-02-02 00:00:00.000000000 +0900
Change: 2015-02-11 11:29:39.369578344 +0900

cpでコピーした場合、コピー先のファイルは、atime,mtime,ctimeが新たに設定される。

$ cp sample_mv.txt sample_cp.txt
$ stat sample_cp.txt
・・・
Access: 2015-02-11 11:29:57.168565611 +0900
Modify: 2015-02-11 11:29:57.168565611 +0900
Change: 2015-02-11 11:29:57.168565611 +0900