head & tail - View File Parts in Linux

From the Linux Commands cheat sheet · File Viewing & Editing · verified Nov 2026

head & tail - View File Parts

View the beginning or end of files

bash
# View first 10 lines
head file.txt

# View first N lines
head -n 20 file.txt

# View last 10 lines
tail file.txt

# View last N lines
tail -n 30 file.txt

# Follow file updates (logs)
tail -f /var/log/syslog
✅ head shows beginning of file, tail shows end
💡 tail -f follows file updates in real-time
🔍 Perfect for monitoring log files as they grow
filesviewlogs

Continue with Linux Commands

Save the full cheat sheet or work through every related task.

More Linux tasks

Back to the full Linux Commands cheat sheet