Sorting a *nix folder by last modification date

Software

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

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

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

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!