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
find
Recursively walks directories evaluating expressions on each entry. Combines discovery with actions like exec or delete.
cp
Copies files and directories from one location to another. Preserves or transforms metadata depending on flags.
mv
Moves or renames files and directories. Within a filesystem it just relinks; across filesystems it copies then deletes.
rm
Removes files and, with -r, directory trees. Deletions are immediate and not recoverable from the shell.
mkdir
Creates one or more directories. Can create nested paths and set the mode of new directories in a single call.