SSH Commands – head

On this page
  1. How the command works
  2. Changing the number of lines
  3. Practical use cases
  4. Working with multiple files
  5. Practical implications
  6. Summary

The head command is used to display the beginning of a file. It is commonly used when working with logs or configuration files to quickly inspect initial lines without opening the full file.

This command is useful when you only need a preview of a file’s content.

How the command works

The basic structure is:

head filename.txt

By default, the command displays the first 10 lines of a file.

Changing the number of lines

You can control how many lines are shown using the -n option.

head -n 5 filename.txt

This example displays only the first 5 lines of the file.

Practical use cases

The head command is commonly used to:

  • preview log files before deeper analysis
  • check configuration file structure
  • verify file content after upload or generation
  • inspect output from other commands in pipelines

Working with multiple files

You can also use head with more than one file:

head file1.txt file2.txt

Each file’s output is displayed separately.

Practical implications

The head command does not modify files. It only reads and displays content, making it safe to use for inspection tasks.

When working with large log files, head helps reduce output and focus only on the earliest entries, which often contain initialization or startup information.

Summary

The head command displays the beginning of a file and helps quickly inspect its content without opening it fully. It is a basic tool for efficient file analysis in SSH environments.

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.