UNIX统计时间格式 [英] UNIX stat time format
本文介绍了UNIX统计时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以格式化统计的时间输出?我使用
与stat -c'%N%A%Z'$文件名
在bash脚本,但它的时间格式是不是我想要的。是否有可能在该命令来改变这种格式,否则我将不得不做手工以后呢?
这是输出示例如下:
/ lib目录drwxr-XR-X 2010-11-15 04:02:38.000000000 -0800
解决方案
您可以尝试是这样的:
日期-D1970-01-01 + $(STAT -c'%Z'$文件名)秒
,让你只有日期。您可以使用日期的格式选项(参见男人日期)格式化日期,例如:
日期-D1970-01-01 + $(STAT -c'%Z'$文件名)秒'+%F%X
这不会给你的名字和权限,但你可以做到这一点,如:
回声$(STAT -c'%N%A'$文件名)$(日期-D1970-01-01 + $(STAT -c'%Z'$文件名)秒'+%F%X')
Is it possible to format the time output of stat? I am using
stat -c '%n %A %z' $filename
in a bash script, but its time format is not what I want. Is it possible to change this format in the command, or would I have to manually do it later?
An example output follows:
/lib drwxr-xr-x 2010-11-15 04:02:38.000000000 -0800
解决方案
You could try something like:
date -d "1970-01-01 + $(stat -c '%Z' $filename ) secs"
Which gives you only the date. You can format the date using date's formatting options (see man date), for example:
date -d "1970-01-01 + $(stat -c '%Z' $filename ) secs" '+%F %X'
This doesn't give you the name and permissions but you may be able to do that like:
echo "$(stat -c '%n %A' $filename) $(date -d "1970-01-01 + $(stat -c '%Z' $filename ) secs" '+%F %X')"
这篇关于UNIX统计时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文