在目录中查找与特定文件大小匹配的最新文件

Find Most Recent File in a Directory That Matches Certain File Size

我需要在匹配 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 -ltr --block-size=MB | grep 3MB

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

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

这应该有效:

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