【问题标题】:Find Most Recent File in a Directory That Matches Certain File Size在与特定文件大小匹配的目录中查找最新文件
【发布时间】:2019-11-28 11:22:52
【问题描述】:

我需要在匹配 3.0 MB 的目录中找到最近修改的文件。

第一次尝试

ls -t /home/weather/some.cool*.file | head -n +1 | grep "3.0M"

第二次尝试

find /home/weather/ -maxdepth 1 -type f -name "some.cool*.file" -size 3M -exec ls -t "{}" +; | head -n +1

我接近了吗?

【问题讨论】:

  • 你试过ls -lh --sort=time | grep "3.0M"吗?
  • 在我将| head -n =1 添加到末尾后效果很好。请提交此评论作为答案。
  • 请务必查看man 页面,在那里可以找到很多有用的信息。 man ls ls 的手册页

标签: linux find ls


【解决方案1】:

我希望这有点用 -

ls -ltr --block-size=MB | grep 3MB

最新修改的文​​件将显示在输出的底部。

-r 标志以相反的顺序显示输出,--block-size=MB 将以 MB 为单位显示文件的大小。

【讨论】:

    【解决方案2】:

    这应该可行:

    ls -lh --sort=time /path/to/directory/*.file | grep "3.0M" | head -n =1

    【讨论】: