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
-
-n [NUM]:- Displays the first
NUMlines of the file. IfNUMis omitted, it defaults to 10. - Example:
head -n 5 filename.txtshows the first 5 lines.
- Displays the first
-
-c [NUM]:- Displays the first
NUMbytes of the file instead of lines. - Example:
head -c 20 filename.txtshows the first 20 bytes.
- Displays the first
-
-q:- Suppresses the output of the file headers when multiple files are specified.
- Example:
head -q file1.txt file2.txtwill show the first lines of both files without repeating their names.
-
-v:- Displays the file headers even when only one file is specified.
- Example:
head -v filename.txtwill show the filename before the output.
-
--help:- Displays help information about the
headcommand and its options.
- Displays help information about the
-
--version:- Displays version information about the
headcommand.
- Displays version information about the
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!
