Sorting a *nix folder by last modification date


In my continuing series of things you already know, unless you don’t, this command sorts the contents of a folder by modification date, then lexicographical:

$ ls -lrt

Nine times out of ten, when I’m browing a folder of logs or assets or anything else, I’m looking at what was last changed. This puts the most recent changes at the bottom, which is useful if the list is longer than my console.

I’ve long since committed this to muscle memory, like a gentleman, but at the time I remembered it by thinking of the Singaporean and Malaysian trains. You may substitute it with your own mnemonic.

You won’t want to use this in a script, but it’s still super useful. Like a banana. And the man pages for FreeBSD, NetBSD, macOS, and GNU/Linux will have more details.

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.