Black Friday Deals for Linux Users are Now Live!
Learn more
Jun 28, 2022 3 min read

ls -lrt Linux Command Explained

Table of Contents

As a software developer or tester, you'll often use the "ls -lrt" command, specially while dealing with a large number of files.

Actually, it's just ls command. The -lrt provides additional options to the command.

If you are looking for an explanation, you are either a new Linux user or don't use Linux commands quite often. No worries. I won't judge you because I have been there myself.

Let me explain things to you.

What does ls -lrt command do?

The ls command is used for listing the contents of a directory. The lrt part is a combination of three different options:

  • l: This is for the long listing of the contents. It shows one file in each line with additional info such as permissions, ownership, size, timestamps etc.
  • t: This one sorts the long listing output based on time.
  • r: This one reverses the order of ls command output.

So when you combine them all, you display the contents in the present directory sorted in reverse chronological order. The newest files are shown at the bottom.

The order of the options doesn't matter here. You'll get the same result for ls -lrt and ls -ltr.

Let's go a little further and understand it with practical examples.

Let me show you the contents of my sample directory:

[email protected]:~/Apps$ ls
balenaEtcher-1.5.116-x64.AppImage  pcloud
cpufetch                           PenguinSubtitlePlayer-Linux
Obsidian-0.13.19.AppImage          ScreenCloud-v1.5.3-x86_64.AppImage

By default, it just gives the name of the files and directories in alphabetical order.

Now, if I use ls -l, it will display one entry per line, still sorted in alphabetical order.

[email protected]:~/Apps$ ls -l
total 304804
-rwxr-xr-x 1 abhishek abhishek 89697412 Feb  3  2021 balenaEtcher-1.5.116-x64.AppImage
drwxr-xr-x 6 abhishek abhishek     4096 Jul 23  2021 cpufetch
-rwxr-xr-x 1 abhishek abhishek 90800704 Jan 24 11:05 Obsidian-0.13.19.AppImage
-rwxr-xr-x 1 abhishek abhishek 57430439 Mar 17 07:52 pcloud
drwxr-xr-x 2 abhishek abhishek     4096 Mar 20  2021 PenguinSubtitlePlayer-Linux
-rwxr-xr-x 1 abhishek abhishek 74170408 Feb 13 20:26 ScreenCloud-v1.5.3-x86_64.AppImage

Pay attention to the time and date. I am going to sort ls command output by size in long listing with ls -lt:

[email protected]:~/Apps$ ls -lt
total 304804
-rwxr-xr-x 1 abhishek abhishek 57430439 Mar 17 07:52 pcloud
-rwxr-xr-x 1 abhishek abhishek 74170408 Feb 13 20:26 ScreenCloud-v1.5.3-x86_64.AppImage
-rwxr-xr-x 1 abhishek abhishek 90800704 Jan 24 11:05 Obsidian-0.13.19.AppImage
drwxr-xr-x 6 abhishek abhishek     4096 Jul 23  2021 cpufetch
drwxr-xr-x 2 abhishek abhishek     4096 Mar 20  2021 PenguinSubtitlePlayer-Linux
-rwxr-xr-x 1 abhishek abhishek 89697412 Feb  3  2021 balenaEtcher-1.5.116-x64.AppImage

Do you notice the change? Now the entries are sorted by time. The newest files are displayed at the top.

Linux shows the time for the files created in the current year. For older files, it shows the year (notice 2021?).

Now, this is good enough if you have a few files. But if you have 20 or 50 or 100 files in the current directory and you want to see which files were accessed or modified recently, this will be a pain. Why? Because you'll have to scroll up to see the newest files.

What you can do here is reverse the sorting and display the newest (created or modified) files at the bottom. This way you don't have to scroll up. You achieve this with ls -lrt as the addition of option r will reverse the sorting (by time):

[email protected]:~/Apps$ ls -lrt
total 304804
-rwxr-xr-x 1 abhishek abhishek 89697412 Feb  3  2021 balenaEtcher-1.5.116-x64.AppImage
drwxr-xr-x 2 abhishek abhishek     4096 Mar 20  2021 PenguinSubtitlePlayer-Linux
drwxr-xr-x 6 abhishek abhishek     4096 Jul 23  2021 cpufetch
-rwxr-xr-x 1 abhishek abhishek 90800704 Jan 24 11:05 Obsidian-0.13.19.AppImage
-rwxr-xr-x 1 abhishek abhishek 74170408 Feb 13 20:26 ScreenCloud-v1.5.3-x86_64.AppImage
-rwxr-xr-x 1 abhishek abhishek 57430439 Mar 17 07:52 pcloud

I hope I made things clear to you and now you know what does ls -lrt command does and why is it used. Enjoy.

Linux Foundation Training
Abhishek Prakash
Creator of Linux Handbook and It's FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries from Agatha Christie and Sherlock Holmes to Columbo & Ellery Queen.
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Linux Handbook.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.