![linux ls 仅显示最近文件的秒数](https://linux22.com/image/1496676/linux%20ls%20%E4%BB%85%E6%98%BE%E7%A4%BA%E6%9C%80%E8%BF%91%E6%96%87%E4%BB%B6%E7%9A%84%E7%A7%92%E6%95%B0.png)
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"