Existem apenas TRÊS valores de tempo distintos armazenados para cada um dos seus arquivos, conforme definido pelo Padrão POSIX : link (consulte a seção Definições base - > 4. Conceitos gerais - > 4.8 Atualização de tempos de arquivo)
Each file has three distinct associated timestamps: the time of last data access, the time of last data modification, and the time the file status last changed. These values are returned in the file characteristics structure struct stat, as described in <sys/stat.h>.
E de :
atime is for Last data access timestamp.
mtime is for Last data modification timestamp.
ctime is for Last file status change timestamp.
Os exemplos a seguir mostram a diferença entre os atime , mtime e ctime , estes exemplos estão no GNU / Linux BASH. Você pode usar stat -x
no Mac OS X ou outro BSD Dist. para ver o formato de saída semelhante.
$ 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
Quando o arquivo acaba de ser criado, três timestamps são os mesmos.
1. atime
Primeiro, vamos acessar os dados do arquivo lendo-os ( less
ou vim
), imprimindo-os ( cat
) ou copiando-os para outro arquivo ( 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
Agora vamos alterar o status do arquivo, alterando a permissão ( chmod
) ou renomeando-a ( 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!
Note que até agora, o conteúdo ( data ) do arquivo ainda é o mesmo de quando foi criado.
3. mtime
Finalmente, vamos modificar o conteúdo do arquivo editando o arquivo.
$ 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. hora de nascimento
Observe também que a versão mais recente de stat
(por exemplo, stat --version 8.13
no Ubuntu 12.04) tem 4 informações de registro de data e hora - o Horário de nascimento (tempo de criação do arquivo). Embora possa não mostrar a hora correta por enquanto:
$ 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: -