Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list recent N files in bash shell?

Tags:

find

bash

shell

ls

How to list most recently modified max N (such as 5) files in bash?

I used

ls -alt 

or

find -mtime 0

to show the recently files but I don't know how to limit the result into 5 records. Maybe find or some other command can be followed in command pipe?

like image 609
herbertD Avatar asked Dec 07 '25 09:12

herbertD


1 Answers

You can use head or tail to limit the number oflines in a pipie:

ls -latr | tail -n5
like image 167
choroba Avatar answered Dec 09 '25 22:12

choroba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!