linux文件的时间格式

背景:

今天观察数据库文件的时候发现:

ls -la *.ibd
-rw-rw---- 1 mysql dba        98304 Sep 25  2012 a.ibd                
-rw-rw---- 1 mysql dba       131072 Oct 12  2012 b.ibd
-rw-rw---- 1 mysql dba        98304 Oct 17 15:34 c.ibd                                 
-rw-rw---- 1 mysql dba        98304 Jan  4 13:33 d.ibd

$stat a.ibd
  File: `a.ibd'
  Size: 98304         Blocks: 192        IO Block: 4096   regular file
Device: 811h/2065d    Inode: 134743266   Links: 1
Access: (0660/-rw-rw----)  Uid: (  502/   mysql)   Gid: (  501/     dba)
Access: 2012-09-25 18:35:15.037849294 +0800
Modify: 2012-09-25 19:20:02.820634436 +0800
Change: 2012-09-25 19:20:02.820634436 +0800

$stat b.ibd
  File: `b.ibd'
  Size: 8246001664    Blocks: 16105488   IO Block: 4096   regular file
Device: 811h/2065d    Inode: 95945504    Links: 1
Access: (0660/-rw-rw----)  Uid: (  502/   mysql)   Gid: (  501/     dba)
Access: 2012-10-30 23:24:39.473915516 +0800
Modify: 2012-11-01 05:06:35.091416693 +0800
Change: 2012-11-01 05:06:35.091416693 +0800

$stat c.ibd  
  File: `c.ibd'
  Size: 98304         Blocks: 192        IO Block: 4096   regular file
Device: 811h/2065d    Inode: 22544608    Links: 1
Access: (0660/-rw-rw----)  Uid: (  502/   mysql)   Gid: (  501/     dba)
Access: 2012-06-14 04:10:26.114518581 +0800
Modify: 2012-10-17 15:34:47.824547168 +0800
Change: 2012-10-17 15:34:47.824547168 +0800

$stat d.ibd
  File: `d.ibd'
  Size: 98304         Blocks: 192        IO Block: 4096   regular file
Device: 811h/2065d    Inode: 125304910   Links: 1
Access: (0660/-rw-rw----)  Uid: (  502/   mysql)   Gid: (  501/     dba)
Access: 2012-08-20 14:04:33.844796019 +0800
Modify: 2013-01-04 13:33:59.944597727 +0800
Change: 2013-01-04 13:33:59.944597727 +0800

        

到这里不知道你发现没有,为什么同样是2012年的表文件,为什么ls -la和stat看到的信息却是不一样的?为什么同样是2012年的文件,为什么有的标注2012年,为什么有的没有标注?

答案:

Linux下,默认如果在6个月之内的"新"文件都是以:"Oct 17 15:34"显示,不带年份,如果超过6个月的"老文件"以:“Mar 30 2012”带年份显示;我们可以添加‘--time-style=style’选型修改查看文件的显示方式具体格式有:

+format

如: --time-style="+%Y-%m-%d %H:%M:%S" 展示的时候就是 ‘2002-03-30 23:45:56’。

ls -l --time-style="+%Y-%m-%d %H:%M:%S"

2013-03-13 00:02:50

full-iso

 

如:ls -l --time-style="+%Y-%m-%d %H:%M:%S.%N %z" 

2013-03-13 00:02:50.000000000 +0800

long-iso

这种格式和ls -l --time-style='+%Y-%m-%d %H:%M'输出的效果是一样的,到分钟级别

2013-03-13 00:02

iso

ls -l --time-style="+%Y-%m-%d $newline%m-%d %H:%M"

ls -l --time-style="iso"

locale

等同于:ls -l --time-style="+%b %e  %Y$newline%b %e %H:%M"

posix-style

 

像这种输出格式Mar 30 2002’ and ‘Mar 30 23:45’ 或 ‘2002-03-30 23:45

文件有3个时间,

last access time: ls -lu filename

last modified time:ls -lm filename

last change to inode information (metadata):ls -lc filename

posted @ 2013-04-16 21:48  sunss  阅读(3331)  评论(0编辑  收藏  举报