bash ls; 输出修改文件的时间,包括年和秒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13999300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:04:15  来源:igfitidea点击:

bash ls; output a time of modification of files including year and seconds

linuxbashls

提问by Andrey Baulin

I want to output a time of modification of files including year and seconds. I tried to use ls -linT, means -T must do it, but it doesn't. -T is recognized as tabulation size. I'm searching a solution using ls. Could someone help me, please?

我想输出包括年和秒在内的文件修改时间。我尝试使用 ls -linT,意味着 -T 必须这样做,但事实并非如此。-T 被认为是制表大小。我正在使用 ls 搜索解决方案。有人可以帮我吗?

回答by perreal

Try --time-style=full-iso, or just --full-time:

尝试--time-style=full-iso,或者只是--full-time

ls -l --time-style=full-iso
ls --full-time

From man-page:

从手册页:

--time-style=STYLE with -l, show times using style STYLE: full-iso, long-iso, iso, locale, +FORMAT. FORMAT is interpreted like date'; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed withposix-', STYLE takes effect only outside the POSIX locale

--time-style=STYLE 和 -l,使用样式 STYLE 显示时间:full-iso、long-iso、iso、locale、+FORMAT。FORMAT 解释为date'; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed withposix-',STYLE 仅在 POSIX 语言环境之外生效

So you can also have a format specifier (see dateman-page for format string):

所以你也可以有一个格式说明符(参见date格式字符串的手册页):

ls -l --time-style=+"%Y %H:%M:%S"