【问题标题】:How to sort the output of recursive “grep -lr” chronologically by newest modification date last?如何按最新修改日期按时间顺序对递归“grep -lr”的输出进行排序?
【发布时间】:2019-02-20 15:35:42
【问题描述】:

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

我无法得到答案

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

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

【问题讨论】:

    标签: grep ls


    【解决方案1】:

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

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

    更稳健地使用 GNU 版本的工具来处理包含外来字符的目录/文件名:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      相关资源
      最近更新 更多