4

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?

Mat
  • 52,586
Tarek
  • 143

2 Answers2

3

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
2

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 {} +