如何使用“查找"命令显示修改后的日期时间? [英] How to display modified date time with 'find' command?
问题描述
使用 find
命令,我可以显示多个级别的目录名称.以下命令显示/var
路径下深度为2的所有目录:
With a find
command, I can display directories names with multiple levels. The following command display all directories under /var
path with a depth of 2:
find /var -maxdepth 2 -type d;
结果显示:
/var
/var/log
/var/log/sssd
/var/log/samba
/var/log/audit
/var/log/ConsoleKit
/var/log/gdm
/var/log/sa
使用 stat
命令,我可以找到修改后的日期时间:
With a stat
command, I can find the modified date time:
stat /var/log/samba | grep 'Modify:'
结果是:
Modify: 2014-01-02 11:21:27.762346214 -0800
有没有办法组合这两个命令,以便列出带有修改日期时间的目录?
Is there a way to combine the two commands so that directories will be listed with modified date time?
推荐答案
您可以使用 -exec
开关来进行 find
并定义 stat 的输出格式
使用 -c
开关如下:
You could use the -exec
switch for find
and define the output format of stat
using the -c
switch as follows:
find/var -maxdepth 2 -type d -exec stat -c "%n %y" {} ;
这应该在输出的同一行给出文件名和修改时间.
This should give the filename followed by its modification time on the same line of the output.
这篇关于如何使用“查找"命令显示修改后的日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!