Debian

How to Sort Files Using “ls” by Last Changed Date in Debian

The ls command is one of the widely used commands in the Linux system that displays the list of files and directories in a Linux system terminal. It is beneficial especially when you have many files in a directory and finding a specific file is a tough task. If you sort the files list based on the last changed date, it could help you quickly access the file on the terminal.

This article presents a detailed guide to sort file using “ls” by the last changed date in Debian.

Debian | Sort “ls” by Last Changed Date

Be default, the “ls” command displays the file list in alphabetical order as shown below:

ls

If you use “-t” parameter with the ls command, it sorts the files list with the time period. The -t stands for time modified and it sorts the files that are recently changed. The general command for sorting the files in which the last changes are made at the top is the following:

ls -t

If you use the -lht with the “ls” command, it sorts the list based on last modified human-readable files in the current directory:

ls -lht

The below command is used for sorting the recently changed files at the bottom in the current directory:

ls -lhrt

To sort the list with the last modified date and time, you can use the -lt parameter with the ls command as shown below:

ls -lt

If you want to sort the list in reverse order with the perspective of the day and time, use the following command in the terminal:

ls -ltr

Bottom Line

The ls command is used to display the files and directories at the current location in the terminal. By default, it displays the list in alphabetical order. By using several flags or parameters with “ls” commands, you can sort files in last changed date order in Debian.

About the author

Zainab Rehman

I'm an author by profession. My interest in the internet world motivates me to write for Linux Hint and I'm here to share my knowledge with others.