Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 查找和排序目录_Linux_Shell_Unix - Fatal编程技术网

Linux 查找和排序目录

Linux 查找和排序目录,linux,shell,unix,Linux,Shell,Unix,我需要找到不超过30天的目录,然后按日期排序(从最新到最旧)。 这是我的命令: find /tmp/logs/ -maxdepth 1 -mindepth 1 -type d -mtime -30 问题显然是排序部分:)如果只有“少数”目录,您可以通过管道查找的输出到xarg ls-t,例如: find /tmp/logs/ -maxdepth 1 -mindepth 1 -type d -mtime -30 | xargs ls -td1 从上面进行查找,然后在最后使用: find-pri

我需要找到不超过30天的目录,然后按日期排序(从最新到最旧)。 这是我的命令:

find /tmp/logs/ -maxdepth 1 -mindepth 1 -type d -mtime -30
问题显然是排序部分:)

如果只有“少数”目录,您可以通过管道
查找
的输出到
xarg ls-t
,例如:

find /tmp/logs/ -maxdepth 1 -mindepth 1 -type d -mtime -30 | xargs ls -td1

从上面进行查找,然后在最后使用:

find-printf“%A@%f\n”| sort-rn

这会告诉find打印时间(以秒为单位)和文件名。你可以按时间排序,就这样。如果需要,用管道将其插入
cut-d”“-f2-
,以减少时间

for f in $(find . -maxdepth 1 -mindepth 1 -type d -mtime -30)
do
    echo -n $f " "
    stat -c %Y $f
done

提供带有修改日期的日志。按秒排序应该很容易。

您不能用结果调用sort吗
find/tmp/logs/-maxdepth 1-mindepth 1-type d-mtime-30 | sort
?对目录进行排序,而不是按时间排序,只按字母顺序排序。