![将查找请求限制为一个结果](https://linux22.com/image/1462306/%E5%B0%86%E6%9F%A5%E6%89%BE%E8%AF%B7%E6%B1%82%E9%99%90%E5%88%B6%E4%B8%BA%E4%B8%80%E4%B8%AA%E7%BB%93%E6%9E%9C.png)
我有以下命令,该命令应递归遍历文件夹并获取上次修改日期 - 这很完美。但是,有时出于某种原因,它会返回多个结果。我怎样才能只返回最上面的一个(上次修改的文件)
命令是:
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