Head Command in Linux


Head Command in Linux

In this article we will learn about Head command in Linux which is most use in log check and read top selected line as per requirements.The head command reads the first ten lines of a any given file name.

Command 1:- The basic syntax of head command is:

#head [options] [file(s)]

For example, the following command will display the first ten lines of the file named ‘head auth.log‘.





If more than one file is given, head will show the first ten lines of each file separately. For example, the following command will show ten lines of each file.




Command 2:- If it is desired to retrieve more number of lines than the default ten, then ‘-n‘ option is used along with an integer telling the number of lines to be retrieved.

For example, the following command will display first 3 lines from the file ‘auth.log‘ file.



In fact, there is no need to use ‘-n‘ option. Just the hyphen and specify the integer without spaces to get the same result as the above command.



Command 3:-The head command can also display any desired number of bytes using ‘-c‘ option followed by the number of bytes to be displayed.

For example, the following command will display the first 45 bytes of given file.

# head -c45 /var/log/yum.log

Jan 10 00:06:49 Updated: openssl-1.0.1e-16.el




Share:

0 comments

Please leave your comments...... Thanks