如何列出 (ls) 目录中最后修改的 5 个文件? [英] How can I list (ls) the 5 last modified files in a directory?

查看:32
本文介绍了如何列出 (ls) 目录中最后修改的 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?

推荐答案

尝试使用 head 或 tail.如果您想要 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

这篇关于如何列出 (ls) 目录中最后修改的 5 个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆