将查找请求限制为一个结果

将查找请求限制为一个结果

我有以下命令,该命令应递归遍历文件夹并获取上次修改日期 - 这很完美。但是,有时出于某种原因,它会返回多个结果。我怎样才能只返回最上面的一个(上次修改的文件)

命令是:

find $1 -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2-  | head

输出为

2015-08-17 21:52:00.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 21:50:43.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 21:44:36.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 18:19:04.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-17 18:15:37.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-15 21:22:23.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-15 18:37:51.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-14 18:07:07.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-14 17:55:53.000000000 +0200 ./path/to/files/that/are/redacted.pdf
2015-08-14 17:46:33.000000000 +0200 ./path/to/files/that/are/redacted.pdf

答案1

在命令末尾添加 -n 1

相关内容