此命令在Mac OS X上有效:
find "$1" -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head
在Linux上,按照原始发布者的要求,请使用stat
代替gstat
。
当然,此答案是user37078的出色解决方案,从评论提升为完整答案。我混合了CharlesBgstat
在Mac OS X 上使用的见解。顺便说一下,我从MacPorts而不是自制软件获得coreutils。
这是我将其打包成一个简单的命令~/bin/ls-recent.sh
以进行重用的方法:
#!/bin/bash
# ls-recent: list files in a dir tree, most recently modified first
#
# Usage: ls-recent path [-10 | more]
#
# Where "path" is a path to target directory, "-10" is any arg to pass
# to "head" to limit the number of entries, and "more" is a special arg
# in place of "-10" which calls the pager "more" instead of "head".
if [ "more" = "$2" ]; then
H=more; N=''
else
H=head; N=$2
fi
find "$1" -type f -print0 |xargs -0 gstat --format '%Y :%y %n' \
|sort -nr |cut -d: -f2- |$H $N