简体   繁体   English

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

[英]Find Most Recent File in a Directory That Matches Certain File Size

I need to find the most recently modified file in a directory that matches 3.0 MB. 我需要在与3.0 MB匹配的目录中找到最近修改过的文件。

First Attempt 第一次尝试

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

Second Attempt 第二次尝试

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

Am I close? 我接近了吗?

I hope this is of some use - 我希望这有一些用处 -

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

The latest modified files will be displayed at the bottom of the output. 最新修改的文​​件将显示在输出的底部。

The -r flag shows the output in reverse order and the --block-size=MB will show the size of files in MB. -r标志以相反的顺序显示输出, - --block-size=MB将以--block-size=MB显示文件的大小。

这应该工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM