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?
Asked
Active
Viewed 7,417 times
2 Answers
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

Dennis Kaarsemaker
- 8,530
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 {} +

Stéphane Chazelas
- 544,893
ls
in bash afaik. – Bernhard Dec 02 '12 at 11:20