Command library / ls
ls
List directory contents
Lists files and directories. On its own it prints names only; options add permissions, owners, sizes, dates and hidden files. During an investigation it is usually the first command you run to see what is really inside a folder.
Practice lsUsage
Options and flags
pathdirectory or file to list (default: the current directory)
-llong format: permissions, owner, size and date
-ashow all files, including hidden ones (names starting with a dot)
-Alike -a, but without the . and .. entries
-hhuman-readable sizes (K, M, G) — use together with -l
-tsort by modification time, newest first
-rreverse the sort order
-Rrecursive: also list every subdirectory
-Ssort by file size, largest first
-dlist the directory itself, not its contents
Examples
ls -la /etcLong listing of /etc including hidden files.
ls -lhLong listing with human-readable sizes.
ls -lt /var/logNewest log files first — where did activity just happen?
ls -R /etc/sshEverything under /etc/ssh, subfolders included.
Common mistakes
Lowercase -r reverses the sort order; capital -R is the recursive one. Options are case-sensitive.
-a adds hidden files, which this listing does not need; extra options change the output.