head Command Builder — Linux head Examples

Linux head Command Builder (Preview First Lines)

The head command is used to preview the first lines or bytes of a file in Linux. This interactive head Command Builder helps you generate precise head commands for quick file inspection.


🚀 What is the head Command?

The head command allows you to:

  • Preview the first lines of any text file
  • Preview the first bytes of a file
  • Inspect CSV headers and log file starts
  • Quickly check file contents without opening an editor

⚙️ Basic Syntax

head [options] FILE
head [options] FILE1 FILE2 ...

🧠 How to Use This head Command Builder

This tool helps you:

  • Choose how many lines or bytes to preview
  • Switch between line mode (-n) and byte mode (-c)
  • Control filename headers for single or multiple files
  • Generate a ready-to-use head command

Workflow

  1. Select the file(s) to preview
  2. Choose line count with -n or byte count with -c
  3. Toggle headers with -q / -v for multi-file output
  4. Copy generated command

🔧 Common head Usage Patterns

Preview First 20 Lines of a Log

head -n 20 app.log

Preview a CSV Header Row

head -n 1 data.csv

Preview the First 100 Bytes

head -c 100 notes.txt

Window Into the Middle of a File (Offset Trick)

tail -n +100 app.log | head -n 20

Show All But the Last 50 Lines

head -n -50 app.log

Control Headers for Multiple Files

head -v file1.log file2.log
head -q file1.log file2.log

⚠️ Important Notes

  • Default is 10 lines: bare head file prints only the first 10 lines
  • Lines vs bytes: -n counts lines, -c counts bytes
  • Headers: -v always shows filenames, -q never shows them
  • NUL-delimited: use -z for zero-terminated lines (e.g. find -print0 output)

✅ Pro Tips

  • Use head -n 1 to grab a CSV header before piping to other tools
  • Combine with tail to window any line range without an editor
  • Use -c to sanity-check binary file signatures safely
  • Add -v when comparing the tops of several files at once