ls Command
The ls command lists directory contents in Linux. It's one of the most frequently used commands for exploring the file system.
Syntax
Description
The ls command displays information about files and directories. By default, it lists the contents of the current directory in alphabetical order.
Key features:
- Lists files and directories
- Shows file permissions and ownership
- Displays file sizes and timestamps
- Can show hidden files
- Supports various sorting options
Common Options
| Option | Description |
|---|---|
-l |
Long format (detailed information) |
-a |
Show all files (including hidden) |
-h |
Human-readable file sizes |
-r |
Reverse order |
-t |
Sort by modification time |
-S |
Sort by file size |
-R |
Recursive (list subdirectories) |
Examples
Basic listing
Lists files and directories in current directory
Long format listing
Shows detailed information including permissions, owner, size, and date
Show all files (including hidden)
Displays all files including those starting with a dot
Long format with hidden files
Combines long format with showing all files
Human-readable file sizes
Shows file sizes in KB, MB, GB format
Sort by modification time
Lists files sorted by modification time (newest first)
Sort by file size
Lists files sorted by size (largest first)
Reverse order
Lists files in reverse alphabetical order
List specific directory
Lists contents of specified directory
Recursive listing
Lists all files and subdirectories recursively