Viewing Files
| Command | Purpose | Best For | Key Features |
|---|---|---|---|
| cat | Display entire file | Small files | - cat = concatenate - Shows full content at once - No scrolling - Simple and fast |
| less | View file with scrolling | Large files | - Scroll up/down - Search ( /word)- Does not load whole file at once - Exit with q |
| more | View file page-by-page | Medium files | - Scroll forward only - Limited backward navigation - Older pager (less advanced than less) |
| head | Show first few lines | Quick preview | - Default: shows first 10 lines - Can set number: head -n 20 file |
| tail | Show last few lines | Logs / last lines | - Default: last 10 lines - Live updates with tail -f file |
Structure:
cat [OPTIONS] [FILE]
less [OPTIONS] FILE
more [OPTIONS] FILE
head [OPTIONS] [FILE]
tail [OPTIONS] [FILE]
head -n number_of_lines filename
tail -n number_of_lines filename
Examples:
cat alphabet.txt # Display entire file
less alphabet.txt # View file with scrolling
more alphabet.txt # View file with scrolling, older/limited version
head alphabet.txt # Show first 10 lines by default
tail alphabet.txt # Show last 10 lines by default
head -n 5 alphabet.txt # Show first 5 lines of the file
tail -n 5 alphabet.txt # Show last 5 lines of the file
Command Line Pipes ( | )
|sends output of one command as input to another.- Helps filter and refine large outputs.
- Commands run left → right; order matters.
- Multiple pipes can be chained.
Examples:
ls /etc | head # show first 10 entries
ls /etc/ssh | nl # number all lines
ls /etc/ssh | nl | tail -5 # number first, then show last 5
ls /etc/ssh | tail -5 | nl # take last 5, then number 1–5
*
ls /etc/ssh → show files
* | → pass output
* nl → number each line
Example:
Used to count files or reference them by number.