Bash

列出自紀元以來帶有時間戳的文件

  • August 5, 2017

我基本上想結合輸出

find /

輸出:

find / | xargs -L1 stat -c%Z

第一個命令列出 / 目錄中的文件,第二個命令列出每個文件的時間戳。我想將這兩者結合起來,這樣我就可以得到文件和時間戳,例如:

/path/to/file 1501834915

如果你有 GNU find,你可以完全使用find

find / -printf '%p %C@\n'

格式說明符是:

     %p     File's name.
     %Ck    File's last status change time in the format specified by
            k, which is the same as for %A.
     %Ak    File's last access time in the  format  specified  by  k,
            which  is  either `@' or a directive for the C `strftime'
            function.  The possible values for k  are  listed  below;
            some  of  them might not be available on all systems, due
             to differences in `strftime' between systems.

             @      seconds  since  Jan.  1,  1970,  00:00  GMT,  with
                    fractional part.

如果您不想要小數部分,請使用s而不是@作為時間格式說明符。(有一些系統沒有s,但 Linux 和 *BSD/OSX 確實有s。)

find / -printf '%p %Cs\n'

引用自:https://unix.stackexchange.com/questions/383883