-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux head tail Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to head and tail on Linux, covering Arch Linux, CachyOS, and other distributions including viewing file beginnings, file endings, and file monitoring.
head shows first lines of file.
tail shows last lines of file.
Uses:
- View beginning: See file start
- View ending: See file end
- Monitor logs: Watch log files
- Quick preview: Preview files
Why they matter:
- File preview: Quick file view
- Log monitoring: Watch logs
- Data inspection: Check data files
Show beginning:
# Show first 10 lines (default)
head file.txt
# Show first 20 lines
head -n 20 file.txt
# Or
head -20 file.txtShow bytes:
# Show first 100 bytes
head -c 100 file.txt
# Byte countShow ending:
# Show last 10 lines (default)
tail file.txt
# Show last 20 lines
tail -n 20 file.txt
# Or
tail -20 file.txtWatch file:
# Follow file (like tail -f)
tail -f log.txt
# Watch for new lines
# Press Ctrl+C to stopWatch logs:
# Follow log file
tail -f /var/log/syslog
# Or journal
journalctl -fWatch several:
# Follow multiple files
tail -f log1.txt log2.txt
# Shows both filesCheck installation:
# Check commands
which head
which tail
# Usually in coreutils
# Install if missing
sudo pacman -S coreutilsThis guide covered head and tail usage, file viewing, and log monitoring for Arch Linux, CachyOS, and other distributions.
- Log Management - System logs
- Journalctl Troubleshooting - Journal logs
-
head Documentation:
man head -
tail Documentation:
man tail
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.