linux ls 仅显示最近文件的秒数

linux ls 仅显示最近文件的秒数

linux coreutils ls 命令在使用“-l”选项时会显示最近文件的时间戳(包括小时和分钟),而对于六个月前和现在之后的文件则显示年份。我希望保留这种针对旧文件和最近文件的行为,并希望为最近文件添加秒数和几十秒。

ls -l /tmp/dir/ 
total 0
-rw-r--r-- 1 user1 users 0 janv.  1  2004 foo1   <==== keep this style for 
                                                       non-recent files

-rw-r--r-- 1 user1 users 0 juin  14 12:32 foo2   <==== add seconds for 
                                                       recent files

答案1

以下是 ls 信息页中的几行:

$ info coreutils 'ls invocation'
...
If FORMAT contains two format strings separated by a newline,
the former is used for non-recent files and the latter for
recent files; if you want output columns to line up, you may
need to insert spaces in one of the two formats.
...
the following two `ls' invocations are equivalent:
     newline='
     '
     ls -l --time-style="+%b %e  %Y$newline%b %e %H:%M"
     ls -l --time-style="locale"

相关内容