Head Command - View File Beginnings | Online Free DevTools by Hexmos

View the beginning of files with the Head command. Display the first N lines or bytes of any file. Free online command-line tool for developers.

Head Command

Understanding the Head Command

The head command is a fundamental utility in Unix-like operating systems used to display the beginning of a file. It's incredibly useful for quickly inspecting the contents of large files without having to open them entirely, which can save time and system resources. By default, head displays the first 10 lines of a file, making it ideal for checking headers, configuration settings, or the start of log entries.

Viewing Specific Number of Lines

You can easily control how many lines are displayed by using the -n option followed by the desired number. This flexibility allows you to tailor the output to your specific needs, whether you need just the first few lines or a more substantial portion of the file's beginning.

# To show the first <number> lines of <file>:
head -n <number> <file>

Displaying a Specific Number of Bytes

In addition to lines, the head command can also display a specific number of bytes from the beginning of a file using the -c option. This is particularly useful when dealing with binary files or when you need to examine the exact byte sequence at the start of a file.

# To show the first <number> bytes of <file>:
head -c <number> <file>

Common Use Cases for Head

The head command is a staple for developers and system administrators. It's frequently used to:

  • Quickly preview configuration files.
  • Inspect the headers of log files to identify issues.
  • Check the first few records of a data file.
  • Verify the integrity of newly created files.

For more in-depth file manipulation, consider exploring related commands like tail, which displays the end of a file.

External Resources