Skip to main content

Command referencels

ls command (Linux / bash / sh / zsh)

Linuxbashshzshfilebeginner

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 / optionMeaning
-lUse a detailed long listing.
-aInclude hidden dotfiles.
-hShow human-readable sizes with -l.
-tSort 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.

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.