files

ls

Lists directory contents including files and subdirectories. Supports detailed views, sorting, and filtering to inspect the filesystem quickly.

ls [OPTION]... [FILE]...

Common flags

Flag Purpose
-l Long listing with permissions, owner, size, and mtime
-a Include entries starting with a dot (hidden files)
-h Human-readable sizes (e.g. 1K, 234M, 2G) with -l
-R Recurse into subdirectories
-t Sort by modification time, newest first
-S Sort by file size, largest first
-r Reverse the sort order

Examples

ls -lah

Long, human-readable listing including hidden files

ls -lt | head

Show the ten most recently modified entries

ls -lSh /var/log

Sort log files by size, largest first

ls -1

One entry per line, ideal for piping into other commands

Gotcha

Parsing ls output in scripts is fragile because filenames may contain spaces or newlines; use find -print0 or globs instead.

Related commands

← All Linux commands · Linux cheat sheet