Linux / Unix: Sort ls Command Output By Last Modified Date and Time

To sort the output of the ls command by last modified date and time, you can use the following command:

$ ls -lt

The -l option will list the files in long format and the -t option will sort the files by last modification time, so the most recently modified files will appear first in the list.

For example:

$ ls -lt
total 8
-rw-rw-r-- 1 user user 26 Feb 5 21:33 file3.txt
-rw-rw-r-- 1 user user 40 Feb 5 21:31 file2.txt
-rw-rw-r-- 1 user user 53 Feb 5 21:29 file1.txt
drwxrwxr-x 2 user user 4096 Feb 5 21:28 dir1

The output shows the files and directories sorted by last modification time, with the most recently modified files appearing first.

Leave a Comment