ls(1)
List directory contents and file information.
Synopsis
ls [OPTION]... [FILE]...Description
Lists files and directories in a directory. By default, output is sorted alphabetically and displayed in columns. When no FILE is specified, lists the current directory.
Most commonly used with flags to control output format, sorting, and what file metadata to display. Can operate recursively and show hidden files.
Common options
| Flag | What it does |
|---|---|
-l | long format; display permissions, owner, size, modification time, and filename |
-a | show all files, including those starting with a dot (.hidden files) |
-h | print file sizes in human-readable format (K, M, G) instead of bytes |
-R | recursively list subdirectories and their contents |
-t | sort by modification time (newest first) |
-S | sort by file size (largest first) |
-r | reverse sort order |
-d | list directories themselves, not their contents |
-i | print inode number before each filename |
-1 | list one file per line (useful for scripts) |
Examples
Show all files in long format, including hidden files and their full details
ls -laList all .txt files in long format with human-readable file sizes
ls -lh *.txtList files sorted by size in ascending order (smallest first)
ls -lSrShow 10 most recently modified files in long format
ls -lt | head -10Recursively list all files and directories under /home/user/project
ls -R /home/user/projectList only subdirectories, not their contents
ls -d */List files with directories shown first, human-readable sizes
ls -lh --group-directories-firstCount the number of .jpg files using one-per-line format
ls -1 *.jpg | wc -l