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"

相關內容