Linux head commandThe 'head' command displays the starting content of a file. By default, it displays starting 10 lines of any file. Syntax: Example: Look at the above snapshot, command "head jtp.txt" has displayed the first ten lines of the file 'jtp.txt'. Head command for multiple filesIf we'll write two file names then it will display first ten lines (in this case file has five lines only) of each file separated by a heading. Syntax: Example: Look at the above snapshot, content of both the files are displayed with a separate heading with the help of "head doc1.txt doc2.txt" command. Linux head -nThe 'head -n' option displays specified number of lines. Syntax: Example: Look at the above snapshot, 15 lines are displayed by the command "head -15 jtp.txt". Note: The above example syntax can also be written as "head -n15 jtp.txt" or "head -n 15 jtp.txt". In all cases result will be same. Linux head -cThe 'head -c' command counts the number of bytes of a file. Syntax: Example: Look at the above snapshot, 20 byte content of file 'jtp.txt' is displayed with the help of command "head -c 20 jtp.txt". Note: Bytes counting has only one syntax unlike lines counting. If you'll use "head -c<number>k <file name>"then it will return the result by multiplying the number by suffix. Suffix can be "b (bytes=512), k(kilobytes=1024) and m (megabytes=1048576)".
Next TopicLinux tail
|