(转)linux 中使用ls指定输出时间格式

时间:2022-01-22 14:33:40

linux 中使用ls指定输出时间格式

原文:http://blog.csdn.net/chaofanwei/article/details/13018753

ls -l --time-style=xxx
   xxx:full-iso, long-iso, iso, locale, +FORMAT

默认输出是:locale格式

例一:ls -l --time-style=full-iso

[wei@localhost ~]$ ls -l --time-style=full-iso
总计 24
drwxr-xr-x 2 boco boco 4096 2013-10-16 14:49:57.000000000 +0800 Deskt
drwxrwxr-x 2 boco boco 4096 2013-10-21 14:55:47.000000000 +0800 telne
drwxr-xr-x 2 boco boco 4096 2013-10-21 14:24:12.000000000 +0800 测试

例二:ls -l --time-style=long-iso

[wei@localhost ~]$ ls -l --time-style=long-iso
总计 24
drwxr-xr-x 2 boco boco 4096 2013-10-16 14:49 Desktop
drwxrwxr-x 2 boco boco 4096 2013-10-21 14:55 telnet目录
drwxr-xr-x 2 boco boco 4096 2013-10-21 14:24 测试

例三:ls -l --time-style=iso

[wei@localhost ~]$ ls -l --time-style=iso
总计 24
drwxr-xr-x 2 boco boco 4096 10-16 14:49 Desktop
drwxrwxr-x 2 boco boco 4096 10-21 14:55 telnet目录
drwxr-xr-x 2 boco boco 4096 10-21 14:24 测试

例四:ls -l --time-style=locale

[wei@localhost ~]$ ls -l --time-style=locale
总计 24
drwxr-xr-x 2 boco boco 4096 10-16 14:49 Desktop
drwxrwxr-x 2 boco boco 4096 10-21 14:55 telnet目录
drwxr-xr-x 2 boco boco 4096 10-21 14:24 测试

例五:ls -l

[wei@localhost ~]$ ls -l
总计 24
drwxr-xr-x 2 boco boco 4096 10-16 14:49 Desktop
drwxrwxr-x 2 boco boco 4096 10-21 14:55 telnet目录
drwxr-xr-x 2 boco boco 4096 10-21 14:24 测试

例六:ls -l --time-style '+%Y/%m/%d %H:%M:%S'

[wei@localhost ~]$ ls -l --time-style '+%Y/%m/%d %H:%M:%S'
总计 24
drwxr-xr-x 2 boco boco 4096 2013/10/16 14:49:57 Desktop
drwxrwxr-x 2 boco boco 4096 2013/10/21 14:55:47 telnet目录
drwxr-xr-x 2 boco boco 4096 2013/10/21 14:24:12 测试

查看linux系统安装时间:(查看/etc的时间)
ls --time-style '+%Y/%m/%d %H:%M:%S' -lct /etc/ | tail -1 | awk '{print $6,$7}'