By default ls -t
sorts output from newest to oldest, so the combination of commands to use depends in which direction you want your output to be ordered.
For the newest 5 files ordered from newest to oldest, use head
to take the first 5 lines of output:
ls -t | head -n 5
For the newest 5 files ordered from oldest to newest, use the -r
switch to reverse ls
's sort order, and use tail
to take the last 5 lines of output:
ls -tr | tail -n 5