What other head command options exist?

087

The head command in Unix-like operating systems has several options that allow you to customize its behavior. Here are some commonly used options:

Common head Command Options

  1. -n [NUM]:

    • Displays the first NUM lines of the file. If NUM is omitted, it defaults to 10.
    • Example: head -n 5 filename.txt shows the first 5 lines.
  2. -c [NUM]:

    • Displays the first NUM bytes of the file instead of lines.
    • Example: head -c 20 filename.txt shows the first 20 bytes.
  3. -q:

    • Suppresses the output of the file headers when multiple files are specified.
    • Example: head -q file1.txt file2.txt will show the first lines of both files without repeating their names.
  4. -v:

    • Displays the file headers even when only one file is specified.
    • Example: head -v filename.txt will show the filename before the output.
  5. --help:

    • Displays help information about the head command and its options.
  6. --version:

    • Displays version information about the head command.

Example Usage

Here’s how you might use some of these options:

head -n 15 filename.txt      # Show the first 15 lines
head -c 50 filename.txt       # Show the first 50 bytes
head -q file1.txt file2.txt   # Show the first lines of both files without headers

Conclusion

These options make the head command versatile for viewing file contents in different ways. If you have more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!