ls
Overview
The ls
command lists directory contents. It’s one of the most frequently used commands in Linux, providing information about files and directories.
Syntax
ls [options] [file/directory...]
Common Options
Option | Description |
---|---|
-l |
Long listing format |
-a |
Show all files (including hidden) |
-h |
Human-readable sizes |
-R |
Recursive listing |
-t |
Sort by modification time |
-S |
Sort by file size |
-r |
Reverse sort order |
-d |
List directories themselves |
-i |
Show inode numbers |
--color |
Colorize output |
Key Use Cases
- List directory contents
- View file permissions
- Check file sizes
- Find recently modified files
- View hidden files
Examples with Explanations
Example 1: Basic Listing
ls -l
Shows detailed listing of current directory
Example 2: All Files with Human Readable Sizes
ls -lah
Shows all files including hidden ones with readable sizes
Example 3: Sort by Time
ls -lt
Lists files sorted by modification time
Understanding Output
Long format (-l) columns: - Permissions (drwxrwxrwx) - Number of links - Owner name - Group name - File size - Last modification time - File/directory name
Common Usage Patterns
List recent files:
ls -lt | head
Find large files:
ls -lSh
List only directories:
ls -ld */
Performance Analysis
- Use with grep for filtering
- Avoid -R on deep directories
- Consider using find for complex searches
- Use -1 for single column output
- Limit directory depth when needed