head command in Linux is used to display the beginning of a file. By default, it displays the first 10 lines of a file. This command is useful when you want to quickly view the contents of a file without opening it in an editor.
To use the
head command, open a terminal window and type the following:
filename with the name of the file you want to view.
head will display the first 10 lines of the file. If you want to display a different number of lines, you can use the
-n option followed by the number of lines you want to display. For example, to display the first 5 lines of a file, you would use the following command:
head -n 5 filename
If you want to display the first part of multiple files, you can specify the filenames as arguments to the
head command. For example:
head file1 file2 file3
This will display the first 10 lines of each file.
The following table lists all the available options for the
||Display the first N bytes of the file.|
||Display the first N lines of the file.|
||Do not print headers when displaying multiple files.|
||Always print headers when displaying multiple files.|
If you receive an error message when using the
head command, make sure that you have typed the command correctly and that you have specified the correct filename. If the file does not exist, you will receive an error message.
If you want to display the first part of a file that is very large, the
head command may not be the best option. In this case, you can use the
less command to view the file and navigate through it.
headcommand only displays the beginning of a file. If you want to view the entire contents of a file, you can use the
- By default, the
headcommand displays 10 lines of a file. This can be changed using the