The head command in Linux and Unix-like systems is used to display the first few lines of a file. By default, it will display the first 10 lines of a file, but this can be modified with options.
Here is the basic syntax for the head command:
head [options] [file]
file is the name of the file you want to display the first few lines of. Here are some examples of the head command:
1. To display the first 10 lines of a file called “file1.txt”:
$ head file1.txt
2. To display the first 20 lines of a file called “file1.txt”
$ head -n 20 file1.txt
Note: The -n option is used to specify the number of lines to display.
3. To display the first 20 lines of a file called “file1.txt” and “file2.txt”
$ head -n 20 file1.txt file2.txt
4. To display the first 10 lines of the output of a command
$ ls -la | head
Note: The | symbol is used to pipe the output of one command to another. In this case it is piping the output of the ls -la command to the head command.
5. To display the first n lines of multiple files
$ head -n 15 file1.txt file2.txt file3.txt
The head command is useful for quickly displaying the first few lines of a file, which can be useful for previewing the contents of a file or for troubleshooting purposes. It is also useful when you have a large file and you only want to see the top of the file without opening it in an editor.
It's important to note that the head command will display the first few lines of the file, regardless of the file type, whether it's text or binary.
The head command can be combined with other commands like grep, sed or awk to manipulate the output or filter it. It's also useful to use head in combination with tail command to display the first and last few lines of a file.
Please also review the tail command, which is quite similar but still different from head. The tail command is useful for displaying the last few lines of a file, which can be useful for monitoring log files in real-time, troubleshooting and previewing the contents of a file. The head command is useful for displaying the first few lines of a file, which can be useful for previewing the contents of a file or for troubleshooting purposes. Both of them are useful when you have a large file and you only want to see a specific part of the file without opening it in an editor.