如何列出目录中的5个最后修改的文件? [英] How can I list (ls) the 5 last modified files in a directory?
本文介绍了如何列出目录中的5个最后修改的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道ls -t
将按修改的时间列出所有文件.但是如何将这些结果限制为仅最后的 n 个文件?
I know ls -t
will list all files by modified time. But how can I limit these results to only the last n files?
推荐答案
尝试使用头部或尾部.如果要最近修改的5个文件:
Try using head or tail. If you want the 5 most-recently modified files:
ls -1t | head -5
-1(即一个)表示每行一个文件,头部表示前5个条目.
The -1 (that's a one) says one file per line and the head says take the first 5 entries.
如果您想要最后5次尝试
If you want the last 5 try
ls -1t | tail -5
这篇关于如何列出目录中的5个最后修改的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文