🐧 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 |
|---|---|
-l | Use a long listing format showing permissions, owner, group, size, and date |
-a | Do not ignore entries starting with . (show all hidden files) |
-h | With -l, print sizes in human readable format (e.g., 1K, 234M, 2G) |
-t | Sort files by modification time, newest first |
-r | Reverse the order of sort |
-S | Sort files by size, largest first |
-R | List subdirectories recursively |
-1 | List 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.