列出自纪元以来带有时间戳的文件

Gam*_*120 6 shell bash find xargs stat

我基本上想结合输出

find /
Run Code Online (Sandbox Code Playgroud)

输出为:

find / | xargs -L1 stat -c%Z
Run Code Online (Sandbox Code Playgroud)

第一个命令列出 / 目录中的文件,第二个命令列出每个文件的时间戳。我想将这两者结合起来,这样我就可以得到文件和时间戳,例如:

/path/to/file 1501834915
Run Code Online (Sandbox Code Playgroud)

mur*_*uru 11

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

find / -printf '%p %C@\n'
Run Code Online (Sandbox Code Playgroud)

格式说明符是:

find / -printf '%p %C@\n'
Run Code Online (Sandbox Code Playgroud)

如果您不需要小数部分,请使用s代替@作为时间格式说明符。(有一些系统没有s,但 Linux 和 *BSD/OSX 确实有s。)

     %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.
Run Code Online (Sandbox Code Playgroud)

  • @Gamer1120 所以用`sed`去除时间戳的小数部分。这仍然比分叉 `stat` 数千次要快得多。例如`find / -printf '%p %C@\n' | sed -e 's/\.[^.]*$//'` (2认同)
  • @Gamer1120 如果您不想要小数部分,请使用 `s` 而不是 `@`。 (2认同)