ls command (Linux / bash / sh / zsh)
What it does
List directory entries and inspect file metadata. When people search for the ls command linux, they usually want ls's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.
List directory entries and inspect file metadata.
Syntax
ls [OPTION]... [FILE]...
Common options
| Flag / option | Meaning |
|---|---|
| -l | Use a detailed long listing. |
| -a | Include hidden dotfiles. |
| -h | Show human-readable sizes with -l. |
| -t | Sort by modification time. |
Practical examples
Inspect a folder
ls -lah /var/log
Lists all log entries with readable sizes.
Newest first
ls -lt
Sorts the current directory by modification time.
Directories only
ls -d */
Shows immediate subdirectories without their contents.
Linux ↔ Windows equivalent
Closest match: Get-ChildItem (Windows / PowerShell). Enumerate items and child items in filesystem, registry, and other providers.
Get-ChildItem is the modern PowerShell equivalent; CMD uses dir.
Common mistakes
- Using `ls -s` when `ls -S` was intended; flags are case-sensitive.
- Parsing formatted `ls` output in scripts instead of using find or shell globs.
Related commands
- findWalk directory trees and select entries using tests and actions.
- pwdPrint the absolute path of the current working directory.
- duEstimate disk usage for files and directory trees.
- cdChange the shell's current working directory.
- dirList files and subdirectories with names, dates, sizes, and attributes.
- Get-ChildItemEnumerate items and child items in filesystem, registry, and other providers.
- cdDisplay or change the current directory in Command Prompt.
- rmRemove files and directory trees permanently.
FAQ
What does ls do in Linux?
List directory entries and inspect file metadata.
How do I use ls from the terminal?
Start with `ls [OPTION]... [FILE]...`, then choose only the options needed for the task.
What is a practical ls example?
Try `ls -lah /var/log` — Lists all log entries with readable sizes.
Can I use ls in a shell script?
Yes. ls works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.