Head
Command name:
Head
Description:
Displays the beginning of a file. By default, head will print the first 10 lines of the file.
syntax/structure:
head [option] [file]
use case:
To break down large files to make reading data easier. Head command allows us to modify the output and display the wanted amount of data.
Options:
-n or --lines shows the specified number of lines
-c or --bytes shows the specified number of bytes
-v or --verbose show the file name tag
-q or --quiet does not separate the content of multiple files with a file name tag
-z, --zero-terminated line delimiter is NUL, not newline
--help display this help and exit
--version output version information and exit
Examples:
1. [user@host ~]$ head file_name // shows first ten lines of a file
2. [user@host ~]$ head -n[4] file_name // -n (4 lines) is used to change the number of lines that are shown starting from the first line of the file
3. [user@host ~]$ head -q file_name1 file_name2 // -q is used when reading the head of two different files, this gives the output of both files together instead of separate
4. [user@host ~]$ head file_name1 file_name2 // using the head command without the -q will display the files' output separately
5. [user@host ~]$ head -c[20] file_name // using -c (number) is used to display 20 bytes of a file
6. [user@host ~]$ head -v file_name // using -v displays the file name followed by the first ten lines of the file
7. [user@host ~]$ head [option] file_name > ouput_file // this command can be used to redirect output to desired folder. If the file does not already exist, it will create the new file
8. [user@host ~]$ [command] | head [option] // the pipeline (|) command allow for a modified output of a command ex: [user@host ~]$ ls/etc | head // will print the first ten files in the etc directory