ls command is used to list all files and directories in linux for the current working directory. By default, ls
command returns the list in alphabetical order. In this tutorial, you will learn how to list and sort files by date and time in Linux or Ubuntu.
List All Files Along With Hidden Files
Use ls -a
or ls --all
command in terminal to display all files and directories along with hidden files for the current working directory.
ls -a
Output:
ls --all
Output:
List Files From Other Directories
Use ls /directory_name
command in terminal to display all files and directories along for the other directory.
** Don’t forget to change directory_name
to available directory name on your computer.
List Files Based on Time and Date
Use ls -t
command in terminal to display files and directories based on modification time and date. The most recently modified files and directories will be shown at the top of the command output.
ls -t
Output:
List Files Based on Time and Date in Reverse Order
Use ls -tr
command in terminal to display files and directories based on modification time and date in reverse order. The most recently modified files and directories will be shown at the bottom of the command output.
ls -tr
Output:
List Files Based on Time and Date in Human Readable Format
Use ls -halt
command in terminal to display files and directories based on modification time and date in a human-readable format. The most recently modified files and directories will be shown at the top of the command output.
** -h
for the human-readable format, and -a
for showing all dot prefixed files or hidden files.
ls -halt
Output: