Linuxのファイルには3つのタイムスタンプがある。
atime … 最終アクセス日時
mtime … 最終変更日時
ctime … 最終ステータス変更日時
■タイムスタンプの表示
ls -lu # atimeの表示 ls -l # mtimeの表示 ls -lc # ctimeの表示
または、statコマンドでも表示できる。
$ stat hoge.txt File: `hoge.txt' Size: 79 Blocks: 8 IO Block: 4096 通常ファイル Device: ca01h/51713d Inode: 139937 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1001/ user) Gid: ( 1001/ user) Access: 2016-05-04 12:20:00.000000000 +0900 # atime Modify: 2016-05-04 12:20:00.000000000 +0900 # mtime Change: 2016-05-05 00:17:00.000000000 +0900 # ctime Birth: -
タイムスタンプを変更するには
atime/mtime は touch コマンドで変更できる。
## mtimeのみ変更 $ touch -m -d "2016/5/10 00:00:00" hoge.txt $ ls -l hoge.txt -rw-r--r-- 1 user group 5 5月 10 00:00 hoge.txt ## atimeのみ変更 $ touch -a -d "2016/5/10 00:00:00" hoge.txt $ ls -lu hoge.txt -rw-r--r-- 1 user group 5 5月 10 00:00 hoge.txt ## atime,mtimeを変更 $ touch -d "2016/5/10 00:00:00" hoge.txt $ ls -l hoge.txt -rw-r--r-- 1 user group 5 5月 10 00:00 hoge.txt $ ls -lu hoge.txt -rw-r--r-- 1 user group 5 5月 10 00:00 hoge.txt ctimeには任意の時刻を設定することはできない。
■find コマンド
findコマンドでは、atime, ctime, mtimeそれぞれでファイルを検索可能
*xx日以前、xx日以降は+xx か −xx か ややこしいので注意!!+xx → xx日以降 ーxx → xx日以内
# ディレクトリ foo が対象とする # 7日前以前にアクセスされたファイルを探す find ./foo -atime +7 # 3日以内に変更されたファイルを探す find ./foo -ctime -3
以上です。