mtime、ctime、atime


Linuxシステムファイルには、create timeではなくctime(change time)、atime(access time)、mtime(modify time)の3つの主要な時間属性があります.その後,atimeの性能問題を解決するためにrelatimeの属性も導入され,以下で説明する.
ctime、多くの友达はそれをcreate timeと理解して、多くの誤解者を含む本もこのように書いています.実際ctimeとはchange timeのことです.
mtimeは、modify time(修正時間)です.
mtimeとctimeの違いは、ファイルの内容を変更した場合にのみファイルのmtimeが更新され、ファイルの名前変更、ファイルの所有者の変更などの操作はctimeのみが更新されることです.
例:ファイルに対してmv操作を行い、mtimeは変わらず、ctimeは更新される.ファイルの内容を編集し、mtimeとctimeを同時に変更します.その他の操作の影響は、自分で試験することができます.しかし、ファイルに対してtouch操作を実行すると、mtimeとctimeが同時に変更されることが分かったので、どの時間を具体的に変更するかは、異なるコマンド自身の実現にかかっています.
atime、これはファイルの内容を見るたびに更新されます.例えばcat操作ですが、ls操作は更新されません.
statでファイルのmtime、ctime、atimeなどのプロパティを表示したり、lsコマンドで表示したりすることができます.具体的には、次のとおりです.
ls-lc filenameリストファイルのctime
ls-lu filenameファイルのatimeをリスト
ls-l filenameファイルのmtimeをリスト
kernel 2から6.29をオンにすると、relatimeのプロパティもデフォルトで統合されます.この機能はatimeの互換性の問題を解決するために個人的に理解しています.ファイル読み込み操作が頻繁なシステムではatime更新によるオーバーヘッドが大きいため、多くのSAではファイルシステムをマウントする際にnoatimeプロパティを使用してatimeの更新を停止している.しかし、一部のプログラムはatimeに基づいていくつかの判断と操作を行う必要があるため、Linuxはrelatime特性を発売した.
このプロパティを使用してファイルシステムをマウントすると、mtimeがatimeより更新された場合にのみatimeが更新されます.実は、この時atimeとmtimeはもう同じものでした.だからこのオプションはatimeの互換性を実現するために発売されたのです.新しい時間プロパティではありません.使用方法はmount-o relatime/dirでディレクトリをマウントすることです.
親ディレクトリへの影響を含め、一般的なシステム呼び出しがこれらの時間に及ぼす影響を明確に示すテーブルがネット上に見つかりました.
On Thu, Oct 05, 2006 at 12:33:57PM -0700, Dmitri V. Ivanov wrote:

> *********************************************************************
> Due to deletion of content types excluded from this list by policy,
> this multipart message was reduced to a single part, and from there
> to a plain text message.
> *********************************************************************

It seems I've failed to send html version...

There is a my opinion about 'Why' and 'How' and next to it my script.
It seems to me too slow. It sorts all files with directory whereas to
sort directories is sufficient. But to sort all files seems to be
usefull to get list of deleted files like uniq.

Why and How:
=========

   First of all about file timestamps and their update [1]in common and table
   with details:

   +-------------------------------------------------+
   |          |  timestamps marked for update  |
   |    syscall  |-------------------------------- |
   |          |   file         |parent dir   |
   |---------------+-------------------+-------------|
   | [2]chdir    |             |         |
   |---------------| -            | -        |
   | [3]fchdir    |             |         |
   |---------------+-------------------+-------------|
   | [4]chmod    |             |         |
   |---------------| ctime         | -        |
   | [5]fchmod    |             |         |
   |---------------+-------------------+-------------|
   | [6]chown    |             |          |
   |---------------|             |         |
   | [7]fchown    | ctime         | -        |
   |---------------|             |         |
   | [8]lchown    |             |         |
   |---------------+-------------------+-------------|
   | [9]close    | -            | -        |
   |---------------+-------------------+-------------|
   | [10]creat    | atime,ctime,mtime | ctime,mtime |
   |---------------+-------------------+-------------|
   | [11]execve   | atime         | -        |
   |---------------+-------------------+-------------|
   | [12]fcntl    | -            | -        |
   |---------------+-------------------+-------------|
   | [13]ftruncate |             |         |
   |---------------| ctime,mtime     | -        |
   | [14]truncate  |             |         |
   |---------------+-------------------+-------------|
   | [15]fstat    |             |         |
   |---------------|             |         |
   | [16]stat    | -            | -        |
   |---------------|             |         |
   | [17]lstat    |             |         |
   |---------------+-------------------+-------------|
   | [18]fsync    |             |         |
   |---------------| -            | -        |
   | [19]fdatasync |             |         |
   |---------------+-------------------+-------------|
   | [20]link    | ctime         | ctime,mtime |
   |---------------+-------------------+-------------|
   | [21]lseek    | -            | -        |
   |---------------+-------------------+-------------|
   | [22]mknod    | atime,ctime,mtime | ctime,mtime |
   |---------------+-------------------+-------------|
   | [23]mkdir    | atime,ctime,mtime | ctime,mtime |
   |---------------+-------------------+-------------|
   | [24]mmap    | *            | -        |
   |---------------+-------------------+-------------|
   | [25]munmap   | -            | -        |
   |---------------+-------------------+-------------|
   | [26]msync    | *            | -        |
   |---------------+-------------------+-------------|
   | [27]open    | *            | *        |
   |---------------+-------------------+-------------|
   | [28]pread    |             |         |
   |---------------|             |         |
   | [29]read    | atime          | -        |
   |---------------|             |          |
   | [30]readv    |              |         |
   |---------------+-------------------+-------------|
   | [31]pwrite   |             |          |
   |---------------|             |          |
   | [32]write    | ctime,mtime     | -        |
   |---------------|             |         |
   | [33]writev   |             |         |
   |---------------+-------------------+-------------|
   | [34]rename   | implementation   | ctime,mtime |
   |---------------+-------------------+-------------|
   | [35]rmdir    | -            | ctime,mtime |
   |---------------+-------------------+-------------|
   | [36]readlink  | *            | -        |
   |---------------+-------------------+-------------|
   | [37]readdir  | atime         | -        |
   |---------------+-------------------+-------------|
   | readahead    | ?            | ?        |
   |---------------+-------------------+-------------|
   | [38]symlink   | *            | *        |
   |---------------+-------------------+-------------|
   | sendfile    | ?            | ?        |
   |---------------+-------------------+-------------|
   | [39]unlink   | -            | ctime,mtime |
   |---------------+-------------------+-------------|
   | [40]utime    | ctime         | -        |
   +-------------------------------------------------+