A Micro Toolbox

ソフトウェアのニッチな問題の対処記録です

lsのファイル日時形式を変える

CentOS 6.4のlsコマンドには--time-styleオプションがあって、ファイルの日付時刻の表示形式をカスタマイズできる。


通常の表示(locale=C)。

$ ls -la
total 28
drwx------  2 xxxx xxxx 4096 Aug 13 22:01 .
drwxr-xr-x. 4 root root 4096 Jun 30 18:46 ..
-rw-------  1 xxxx xxxx  138 Aug 13 22:01 .bash_history
-rw-r--r--  1 xxxx xxxx   18 Feb 22 06:09 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 Feb 22 06:09 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 Aug 13 22:01 .bashrc
-rw-------  1 xxxx xxxx  720 Aug 13 22:01 .viminfo
$ 


ls -l--full-timeで秒まで出力。

$ ls -a --full-time
total 28
drwx------  2 xxxx xxxx 4096 2013-08-13 22:01:54.049744405 +0900 .
drwxr-xr-x. 4 root root 4096 2013-06-30 18:46:13.185533907 +0900 ..
-rw-------  1 xxxx xxxx  138 2013-08-13 22:01:54.049744405 +0900 .bash_history
-rw-r--r--  1 xxxx xxxx   18 2013-02-22 06:09:50.000000000 +0900 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 2013-02-22 06:09:50.000000000 +0900 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 2013-08-13 22:01:51.797735267 +0900 .bashrc
-rw-------  1 xxxx xxxx  720 2013-08-13 22:01:51.799735227 +0900 .viminfo
$


ls -l --time-style=locale。

$ ls -la --time-style=locale
total 28
drwx------  2 xxxx xxxx 4096 Aug 13 22:01 .
drwxr-xr-x. 4 root root 4096 Jun 30 18:46 ..
-rw-------  1 xxxx xxxx  138 Aug 13 22:01 .bash_history
-rw-r--r--  1 xxxx xxxx   18 Feb 22 06:09 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 Feb 22 06:09 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 Aug 13 22:01 .bashrc
-rw-------  1 xxxx xxxx  720 Aug 13 22:01 .viminfo
$
$ locale
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=
$


ls -l --time-style=iso。
long-isoだと年まで表示。
full-isoだと--full-timeと同じく秒まで表示。

$ ls -la --time-style=iso   
total 28
drwx------  2 xxxx xxxx 4096 08-13 22:01 .
drwxr-xr-x. 4 root root 4096 06-30 18:46 ..
-rw-------  1 xxxx xxxx  138 08-13 22:01 .bash_history
-rw-r--r--  1 xxxx xxxx   18 02-22 06:09 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 02-22 06:09 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 08-13 22:01 .bashrc
-rw-------  1 xxxx xxxx  720 08-13 22:01 .viminfo
$
$ ls -la --time-style=long-iso
total 28
drwx------  2 xxxx xxxx 4096 2013-08-13 22:01 .
drwxr-xr-x. 4 root root 4096 2013-06-30 18:46 ..
-rw-------  1 xxxx xxxx  138 2013-08-13 22:01 .bash_history
-rw-r--r--  1 xxxx xxxx   18 2013-02-22 06:09 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 2013-02-22 06:09 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 2013-08-13 22:01 .bashrc
-rw-------  1 xxxx xxxx  720 2013-08-13 22:01 .viminfo
$
$ ls -la --time-style=full-iso
total 28
drwx------  2 xxxx xxxx 4096 2013-08-13 22:01:54.049744405 +0900 .
drwxr-xr-x. 4 root root 4096 2013-06-30 18:46:13.185533907 +0900 ..
-rw-------  1 xxxx xxxx  138 2013-08-13 22:01:54.049744405 +0900 .bash_history
-rw-r--r--  1 xxxx xxxx   18 2013-02-22 06:09:50.000000000 +0900 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 2013-02-22 06:09:50.000000000 +0900 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 2013-08-13 22:01:51.797735267 +0900 .bashrc
-rw-------  1 xxxx xxxx  720 2013-08-13 22:01:51.799735227 +0900 .viminfo
$


dateコマンドの書式。

$ ls -la --time-style=+'%F %T'
total 28
drwx------  2 xxxx xxxx 4096 2013-08-13 22:01:54 .
drwxr-xr-x. 4 root root 4096 2013-06-30 18:46:13 ..
-rw-------  1 xxxx xxxx  138 2013-08-13 22:01:54 .bash_history
-rw-r--r--  1 xxxx xxxx   18 2013-02-22 06:09:50 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 2013-02-22 06:09:50 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 2013-08-13 22:01:51 .bashrc
-rw-------  1 xxxx xxxx  720 2013-08-13 22:01:51 .viminfo
$
$ ls -la --time-style=+'%D'
total 28
drwx------  2 xxxx xxxx 4096 08/13/13 .
drwxr-xr-x. 4 root root 4096 06/30/13 ..
-rw-------  1 xxxx xxxx  138 08/13/13 .bash_history
-rw-r--r--  1 xxxx xxxx   18 02/22/13 .bash_logout
-rw-r--r--  1 xxxx xxxx  176 02/22/13 .bash_profile
-rw-r--r--  1 xxxx xxxx  141 08/13/13 .bashrc
-rw-------  1 xxxx xxxx  720 08/13/13 .viminfo
$