如何按最新修改日期按时间顺序对递归“grep -lr”的输出进行排序?

问题描述 投票:0回答:1

我想获取当前目录或任何子目录中包含按修改日期排序的特定字符串的所有文件的列表。

我无法得到答案

How to sort the output of "grep -l" chronologically by newest modification date last?

为了递归grep搜索而工作。如何获得这样一个有序列表,以便真正包含grep -lr找到的所有文件。

grep ls
1个回答
1
投票

假设您的文件名不包含换行符:

find dir -type f -printf '%T@\t%p\n' | sort | cut -f2- | xargs grep -l whatever

使用GNU版本的工具更有力地处理包含exoctic字符的目录/文件名:

find dir -type f -printf '%T@\t%p\0' | sort -z | cut -z -f2- | xargs -0 grep -l whatever
© www.soinside.com 2019 - 2024. All rights reserved.