2012-02-07 14:59:56 +0000 2012-02-07 14:59:56 +0000
54
54
Advertisement

ファイルのすべてのタイムスタンプをチェックするには?

Advertisement

Linuxでファイルのすべてのタイムスタンプをチェックするコマンドはありますか?

ファイルの最終修正日、作成日、タッチした日付を確認しようとしています。

Advertisement
Advertisement

回答 (2)

75
75
75
2012-02-07 15:03:39 +0000

コマンドは stat という名前です。

$ stat test
234881026 41570368 -rw-r--r-- 1 werner staff 0 0 "Feb 7 16:03:06 2012" "Feb 7 16:03:06 2012" "Feb 7 16:03:06 2012" "Feb 7 16:03:06 2012" 4096 0 0 test

フォーマットを調整したい場合はマニュアルページを参照してください。

一般的には、通常のディレクトリリストからも時刻を取得することができます。

  • ls -l はファイルの内容が最後に変更された時間、mtime
  • ls -lc はファイルの状態が最後に変更された時間、ctime 何が違うのか )
  • ls -lu は最後にアクセスした時間、atime を出力する (この概念の有用性については (http://lwn.net/Articles/244829/))

そしてもちろん、ctime はファイルが「作成」された時間を記録しない。POSIX仕様では3つのタイムスタンプしか定義されていませんが、 Linuxファイルシステムの中にはにBirth Time/Creation Timeを格納しているものもあります。そのようなサポートされた設定では、

stat --printf '%n\nmtime: %y\nctime: %z\natime: %x\ncrtime:%w\n'

0x1& を使うことができます。

21
21
21
2014-03-15 09:24:38 +0000

各ファイルには、POSIX Standardで定義されているように、THREEの異なる時刻値しか保存されていません : http://pubs.opengroup.org/onlinepubs/9699919799/ (Base Definitions のセクション -> 4.8 File Times Update を参照してください。一般概念 -> 4.8 File Times Update)

各ファイルは、3つの異なる関連するタイムスタンプを持っています:最後に データにアクセスした時刻 、最後に データを変更した時刻 、および ファイルの状態が最後に変更された時刻 です。これらの値は、 【<sys/stat.h> _.で説明されているように、ファイル特性構造体 struct statに返されます。

そして、_から :

atime is for Last data access timestamp.
mtime is for Last data modification timestamp.
ctime is for Last file status change timestamp.

以下の例では、atime , mtime , ctime の違いを示していますが、これらの例はGNU/Linux BASHでのものです。Mac OS Xやその他のBSD Dist.では、stat -xを使用して同様の出力形式を見ることができます。

$ stat --version
stat (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Michael Meskes.
$
$ touch test
$ stat test
  File: `test'
  Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:58:28.609223953 +0800
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 10:58:28.609223953 +0800

ファイルが作成されたばかりの場合、3つのタイムスタンプが同じになります。

1. atime

まず、ファイルのデータを読み込む(lessまたはvim)、印刷する(cat)、または別のファイルにコピーする(cp)ことで**アクセスしてみましょう。

$ cat test #Nothing will be printed out, since the file is empty
$ stat test
  File: `test'
  Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800 <-- atime Changed!
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 10:58:28.609223953 +0800

2. ctime

ここで、パーミッションの変更(chmod)やファイル名の変更(mv)により、ファイルの状態を**変更してみましょう

$ chmod u+x test
$ stat stet
  File: `test'
  Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0764/-rwxrw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 11:04:10.178285430 +0800 <-- ctime Changed!
$    
$ mv test testing
$ stat testing
  File: `testing'
  Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0764/-rwxrw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800
Modify: 2014-03-16 10:58:28.609223953 +0800
Change: 2014-03-16 11:06:33.342207679 +0800 <-- ctime Changed again!

ここまでは、ファイルの内容( data )は作成時のままであることに注意してください。


3. mtime

最後に、ファイルを編集して、ファイルの内容を***変更してみましょう。

$ echo 'Modify the DATA of the file' > testing
$ echo 'Modify the DATA of the file also change the file status' > testing
$ stat testing
  File: `testing'
  Size: 56 Blocks: 8 IO Block: 4096 regular file
Device: 811h/2065d Inode: 98828525 Links: 1
Access: (0764/-rwxrw-r--) Uid: ( 514/ rank) Gid: ( 514/ rank)
Access: 2014-03-16 10:59:13.182301069 +0800
Modify: 2014-03-16 11:09:48.247345148 +0800 <-- mtime Changed!
Change: 2014-03-16 11:09:48.247345148 +0800 <-- ctime also Changed!

4.誕生時間

また、statの新しいバージョン(Ubuntu 12.04のstat --version 8.13など)では、4番目のタイムスタンプ情報、誕生時間(ファイル作成時間)があるので注意してください。今のところ正しい時刻を表示していないかもしれませんが。

$ stat --version
stat (GNU coreutils) 8.13
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Michael Meskes.
$
$ stat birth_time
  File: `birth_time'
  Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 805h/2053d Inode: 4073946 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ bingyao) Gid: ( 1000/ bingyao)
Access: 2014-03-16 10:46:48.838718970 +0800
Modify: 2014-03-16 10:46:48.838718970 +0800
Change: 2014-03-16 10:46:48.838718970 +0800
 Birth: -
Advertisement

関連する質問

6
10
5
37
16
Advertisement