Skip to content

Linux head tail Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux head and tail Guide

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.


Table of Contents

  1. Understanding head and tail
  2. head Usage
  3. tail Usage
  4. Following Files
  5. Troubleshooting

Understanding head and tail

What are head and tail?

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

head Usage

First Lines

Show beginning:

# Show first 10 lines (default)
head file.txt

# Show first 20 lines
head -n 20 file.txt

# Or
head -20 file.txt

First Bytes

Show bytes:

# Show first 100 bytes
head -c 100 file.txt

# Byte count

tail Usage

Last Lines

Show ending:

# Show last 10 lines (default)
tail file.txt

# Show last 20 lines
tail -n 20 file.txt

# Or
tail -20 file.txt

Follow File

Watch file:

# Follow file (like tail -f)
tail -f log.txt

# Watch for new lines
# Press Ctrl+C to stop

Following Files

Monitor Logs

Watch logs:

# Follow log file
tail -f /var/log/syslog

# Or journal
journalctl -f

Multiple Files

Watch several:

# Follow multiple files
tail -f log1.txt log2.txt

# Shows both files

Troubleshooting

head/tail Not Found

Check installation:

# Check commands
which head
which tail

# Usually in coreutils
# Install if missing
sudo pacman -S coreutils

Summary

This guide covered head and tail usage, file viewing, and log monitoring for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally