Ryan Ryan - 1 year ago 120
Linux Question

How can I list (ls) the 5 last modified files in a directory?

I know

ls -t
will list all files by modified time. But how can I limit these results to only the last n files?

Answer Source

Try using head or tail. If you want the 5 most-recently modified files:

ls -1t | head -5

The -1 (that's a one) says one file per line and the head says take the first 5 entries.

If you want the last 5 try

ls -1t | tail -5
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download