Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I list the 10 most recently modified files of a certain extension, not all files, or the files modified during the last 2 days for example?

share|improve this question
up vote 2 down vote accepted

You can use find for this. Let's say we want all .py files in the current directory modified in the last 2 days:

find -maxdepth 1 -name '*.py' -mtime -2
share|improve this answer

With zsh

ls -ld -- *.ext(om[1,10])

for the last two days:

ls -ld -- *.ext(m-2)

Otherwise, if filenames don't contain newline characters, you can always do:

ls -lrtd -- *.ext | tail -n 10

And for files modified in the last two days POSIXly:

find . ! -name . -prune -name '*.ext' -mtime -2 -exec ls -ld {} +
share|improve this answer
I am using bash. How can I alter the last command for a specific number of days or files ? – Tarek Dec 2 '12 at 11:14
There is no easy way to do this with plain ls in bash afaik. – Bernhard Dec 2 '12 at 11:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.