🐧 Linux ls Command

List files and directories with metadata including permissions, ownership, sizes, and timestamps.

Syntax

$ ls [options] [directory_or_file]

Common Command Options

Option Description
-lUse a long listing format showing permissions, owner, group, size, and date
-aDo not ignore entries starting with . (show all hidden files)
-hWith -l, print sizes in human readable format (e.g., 1K, 234M, 2G)
-tSort files by modification time, newest first
-rReverse the order of sort
-SSort files by size, largest first
-RList subdirectories recursively
-1List one file per line (ideal for piping to scripts)

Practical Examples

Standard Long Listing
ls -lh
Displays all visible files in long format with readable file sizes in KB, MB, and GB.
Show Hidden Files & Folders
ls -la
Shows all dotfiles (.bashrc, .git, .env) alongside standard files.
Sort by Most Recently Modified
ls -lht
Puts the most recently edited files at the top of the terminal output.
Sort by File Size (Largest First)
ls -lhS
Helps identify huge log files or assets consuming disk storage.
List Only Directories
ls -d */
Filters listing to only display subdirectories.