Linux tutorial on the ls command, covering basic and advanced directory listing with practical examples.
last modified March 3, 2025
The ls command in Linux is used to list the contents of a directory. It is one of the most frequently used commands for navigating and managing files and directories. This tutorial covers basic and advanced usage of ls with practical examples.
ls is commonly used for viewing files, directories, and their properties such as permissions, size, and modification dates.
This example demonstrates how to list the contents of the current directory.
ls
The ls command outputs the names of files and directories in the current directory.
This example shows how to list directory contents in a detailed, long format.
ls -l
The -l option displays file permissions, ownership, size, and modification date.
This example demonstrates how to list hidden files (those starting with a dot).
ls -a
The -a option includes hidden files in the output.
This example shows how to list files with sizes in a human-readable format.
ls -lh
The -h option formats file sizes in KB, MB, or GB.
This example demonstrates how to list files sorted by modification time.
ls -lt
The -t option sorts files by modification time, newest first.
This example shows how to list files in reverse order.
ls -r
The -r option reverses the order of the output.
This example demonstrates how to list files recursively in subdirectories.
ls -R
The -R option lists files in the current directory and all subdirectories.
This example shows how to list files with indicators for file types.
ls -F
The -F option appends symbols like / for directories and * for executables.
This example demonstrates how to list files with their inode numbers.
ls -i
The -i option displays the inode number of each file.
This example shows how to list files with colorized output for better readability.
ls –color
The –color option colorizes the output based on file types.
Use Aliases: Create aliases for frequently used ls options.
Combine Options: Combine options like -l, -h, and -a for detailed output.
Redirect Output: Use > to save directory listings to a file.
Check Permissions: Use -l to verify file permissions and ownership.
In this article, we have explored various examples of using the ls command for listing directory contents, including advanced features like sorting, recursive listing, and colorized output.
My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.
List all Linux tutorials.