linux修改 ls 命令的时间显示格式

一直不习惯 ll 命令将时间日期格式显示为 周名和月名,想要纯粹的 数字格式,找了好久,终于想到一个办法--alias。

[root@localhost ~]# alias    #显示当前已存在的alias
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@localhost ~]# alias ls='ls --color=auto --time-style +"%T %F"'
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog
[root@localhost ~]# ls -l
total 20
-rw-------. 1 root root 1096 17:49:45 2015-05-29 anaconda-ks.cfg
-rw-r--r--. 1 root root 8815 17:49:42 2015-05-29 install.log
-rw-r--r--. 1 root root 3384 17:48:28 2015-05-29 install.log.syslog
[root@localhost ~]# ll
total 20
-rw-------. 1 root root 1096 17:49:45 2015-05-29 anaconda-ks.cfg
-rw-r--r--. 1 root root 8815 17:49:42 2015-05-29 install.log
-rw-r--r--. 1 root root 3384 17:48:28 2015-05-29 install.log.syslog
[root@localhost ~]# date
Tue Dec 29 13:47:21 CST 2015
[root@localhost ~]# date +"%T %F"
13:49:51 2015-12-29
[root@localhost ~]# date +'%T %F' 
13:50:34 2015-12-29
[root@localhost ~]# alias date='date +"%T %F"' 
[root@localhost ~]# date
13:51:12 2015-12-29
[root@localhost ~]# cal
    December 2015   
Su Mo Tu We Th Fr Sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

[root@localhost ~]#

上面的方法只是临时修改,重启后就会失效,要想永久生效,需要修改 /root/.bashrc 文件。

两种修改方法:

  1、用vim编辑  .bashrc,添加两条,然后:wr 保存:

alias date='date +"%T %F"'
alias ls='ls --color=auto --time-style +"%T %F"'

2、使用cat 追加:

cat >> .bashrc << EOF
alias date='date +"%T %F"'
alias ls='ls --color=auto --time-style +"%T %F"'
EOF
cat可以追加EOF标记之间的内容到文件末尾,EOF可以其它是任意的字符串。这种方法在脚本中尤为有用。

 

大笑大笑大笑

posted @ 2015-12-29 14:15  ValiantJiang  阅读(2486)  评论(0编辑  收藏  举报