ls Command Guide
The ls command is one of the most frequently used commands in Linux. Learn how to list directory contents effectively with various options.
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
lsList current directoryls /pathList specific pathls *.txtList files matching patternDisplay
-lLong format with details-aShow hidden files-hHuman-readable sizesSorting
-tSort by modification time-SSort by file size-rReverse sort orderCommon Combos
ls -laAll files with detailsls -lhDetails with readable sizesls -ltDetails sorted by timeDownloadable Image Preview
Basic Usage
The ls command lists information about files and directories. By default, it lists the contents of the current directory.
lsYou can also specify a path to list:
ls /home/user/documentsCommon Options
ls has many options to customize its output. Here are the most commonly used ones.
Long listing format (-l)
ls -lShows detailed information including permissions, owner, size, and modification date.
Show hidden files (-a)
ls -aLists all files including hidden files (those starting with a dot).
Human-readable sizes (-h)
ls -lhDisplays file sizes in human-readable format (K, M, G).
Sort by time (-t)
ls -ltSorts files by modification time, newest first.
Common Options
| -l | Long listing format with details |
| -a | Show all files including hidden |
| -h | Human-readable file sizes |
| -t | Sort by modification time |
| -r | Reverse order |
| -S | Sort by file size |
| -R | List subdirectories recursively |
Practical Examples
List all files with details
ls -laList only directories
ls -d */List files sorted by size
ls -lhSList recently modified files
ls -lt | head -10List files with specific extension
ls *.txtls -lahS to show all files with human-readable sizes, sorted by size.Understanding the Output
When using ls -l, each line shows:
-rw-r--r-- 1 user group 4096 Jan 15 10:30 file.txt
drwxr-xr-x 2 user group 4096 Jan 15 10:30 directory/- File type and permissions (
-rw-r--r--) - Number of hard links
- Owner name
- Group name
- File size in bytes
- Last modification date and time
- File or directory name
- for regular files, d for directories, and l for symbolic links.Summary
The ls command is essential for navigating and understanding your filesystem. Key takeaways:
- Use
ls -lfor detailed file information - Use
ls -ato see hidden files - Combine options like
ls -lahfor complete listings - Use
ls -ltto find recently modified files
Official Documentation
For authoritative information, refer to the official documentation: