The ls command is the most widely used command to display the contents in a directory on a Linux/Mac device terminal.
If you want to sort the output of the ls command by date and time you can make use of the -t option along with the ls -l command,
% ls -lt
total 60
drwx------ 1 root root 4096 Aug 7 17:28 root
drwxrwxrwt 1 root root 4096 Aug 7 17:20 tmp
drwxr-xr-x 5 root root 360 Aug 7 16:52 dev
dr-xr-xr-x 13 root root 0 Aug 7 16:52 sys
dr-xr-xr-x 180 root root 0 Aug 7 16:52 proc
drwxr-xr-x 1 root root 4096 Jul 31 17:20 etc
drwxr-xr-x 1 root root 4096 Jul 31 16:57 run
drwxr-xr-x 1 root root 4096 Jul 31 16:56 home
drwxr-xr-x 1 root root 4096 Apr 5 05:17 var
drwxr-xr-x 2 root root 4096 Apr 5 05:01 media
drwxr-xr-x 2 root root 4096 Apr 5 05:01 mnt
drwxr-xr-x 2 root root 4096 Apr 5 05:01 opt
drwxr-xr-x 2 root root 4096 Apr 5 05:01 srv
drwxr-xr-x 1 root root 4096 Apr 5 05:01 usr
lrwxrwxrwx 1 root root 7 Apr 5 05:01 bin -> usr/bin
lrwxrwxrwx 1 root root 7 Apr 5 05:01 lib -> usr/lib
lrwxrwxrwx 1 root root 8 Apr 5 05:01 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Apr 15 2020 boot
In order to display the latest files and directories first as a list make use of -r option as well along with -lt
% ls -ltr
total 60
drwxr-xr-x 2 root root 4096 Apr 15 2020 boot
lrwxrwxrwx 1 root root 8 Apr 5 05:01 sbin -> usr/sbin
lrwxrwxrwx 1 root root 7 Apr 5 05:01 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Apr 5 05:01 bin -> usr/bin
drwxr-xr-x 1 root root 4096 Apr 5 05:01 usr
drwxr-xr-x 2 root root 4096 Apr 5 05:01 srv
drwxr-xr-x 2 root root 4096 Apr 5 05:01 opt
drwxr-xr-x 2 root root 4096 Apr 5 05:01 mnt
drwxr-xr-x 2 root root 4096 Apr 5 05:01 media
drwxr-xr-x 1 root root 4096 Apr 5 05:17 var
drwxr-xr-x 1 root root 4096 Jul 31 16:56 home
drwxr-xr-x 1 root root 4096 Jul 31 16:57 run
drwxr-xr-x 1 root root 4096 Jul 31 17:20 etc
dr-xr-xr-x 181 root root 0 Aug 7 16:52 proc
dr-xr-xr-x 13 root root 0 Aug 7 16:52 sys
drwxr-xr-x 5 root root 360 Aug 7 16:52 dev
drwxrwxrwt 1 root root 4096 Aug 7 17:20 tmp
drwx------ 1 root root 4096 Aug 7 17:32 root
Conclusion:
- ls -l: l option to displays the output as a list
- ls -lt: t option to display list in order of oldest date to lastest date and time
- ls -ltr: tr option to display list in order of lastest date to oldest date and time
More Posts related to Linux,
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
More Posts:
- VS Code: The source path must be contained in the project root folder. - Java
- Java 8 Display time in 12 hour AM PM format - Java
- [Solved] SharePoint Access Denied error editing Document Name - SharePoint
- Open Docker from Terminal Command on Mac - MacOS
- Add Current Date and Time in Notepad++ - NotepadPlusPlus
- How to Download and Install Roblox Studio on Mac (M1/M2/Intel) - MacOS
- How to Peek into tabs in Notepad++ using Document Peeker - NotepadPlusPlus
- How to find version of Cargo in Rust - Rust