linux下修改ls显示的时间格式

问题引入

在linux工作时经常会遇到需要定时监控文件变化的情况(如文件更新,数据大小变化等),系统默认ls -l显示只精确到分钟,如果能够精确到秒就非常方便直观了,因此我尝试修改ls显示格式来实现,如下:

1.系统默认显示格式

[liul@test dataload]$ ls -l
total 28896
drwxr-xr-x 8 liul liul     4096 Sep 24 17:10 PyYAML-3.10
-rw-r--r-- 1 liul liul   241524 Sep 24 16:40 PyYAML-3.10.tar.gz
-rwxr-xr-x 1 liul liul 14466821 Feb 16  2012 greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.bin
-rw-r--r-- 1 liul liul 14304561 Mar  1  2012 greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.zip
drwxrwxr-x 5 liul liul     4096 Oct  9 17:53 install
drwxrwxr-x 2 liul liul     4096 Oct  9 17:58 shell
drwxr-xr-x 8 liul liul     4096 Oct  9 23:51 yaml-0.1.4
-rw-r--r-- 1 liul liul   471759 Sep 24 16:47 yaml-0.1.4.tar.gz

2.修改ls显示格式后效果

[liul@test dataload]$ ls -l --time-style '+%Y/%m/%d %H:%M:%S'
total 28896
drwxr-xr-x 8 liul liul     4096 2012/09/24 17:10:17 PyYAML-3.10
-rw-r--r-- 1 liul liul   241524 2012/09/24 16:40:10 PyYAML-3.10.tar.gz
-rwxr-xr-x 1 liul liul 14466821 2012/02/16 00:23:25 greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.bin
-rw-r--r-- 1 liul liul 14304561 2012/03/01 17:14:16 greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.zip
drwxrwxr-x 5 liul liul     4096 2012/10/09 17:53:00 install
drwxrwxr-x 2 liul liul     4096 2012/10/09 17:58:26 shell
drwxr-xr-x 8 liul liul     4096 2012/10/09 23:51:18 yaml-0.1.4
-rw-r--r-- 1 liul liul   471759 2012/09/24 16:47:13 yaml-0.1.4.tar.gz


2.1 修改配置到bash_profile

[liul@test dataload]$ vi ~/.bash_profile 
[liul@test dataload]$ source ~/.bash_profile 
[liul@test dataload]$ cat ~/.bash_profile | grep TIME
export TIME_STYLE='+%Y/%m/%d %H:%M:%S'
[liul@test dataload]$ source ~/.bash_profile

2.2 系统变量生效

[liul@test dataload]$ ls -l
total 28896
drwxr-xr-x 8 liul liul     4096 2012/09/24 17:10:17 PyYAML-3.10
-rw-r--r-- 1 liul liul   241524 2012/09/24 16:40:10 PyYAML-3.10.tar.gz
-rwxr-xr-x 1 liul liul 14466821 2012/02/16 00:23:25 greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.bin
-rw-r--r-- 1 liul liul 14304561 2012/03/01 17:14:16 greenplum-loaders-4.2.1.0-build-2-RHEL5-x86_64.zip
drwxrwxr-x 5 liul liul     4096 2012/10/09 17:53:00 install
drwxrwxr-x 2 liul liul     4096 2012/10/09 17:58:26 shell
drwxr-xr-x 8 liul liul     4096 2012/10/09 23:51:18 yaml-0.1.4
-rw-r--r-- 1 liul liul   471759 2012/09/24 16:47:13 yaml-0.1.4.tar.gz
[liul@test dataload]$


这样,在使用watch -n 1 ls -l dataload命令时就可以直观的查看精确到秒级的变化了。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值