10. head command - muneeb-mbytes/linux_course GitHub Wiki
head command is a command-line utility, which prints the first 10 lines of the specified files. If more than one file name is provided then data from each file is preceded by its file name.
Fig-1: All variations of head command
Sr.no | head commands | description |
---|---|---|
1 | head | prints only the first 10 lines of the file |
2 | head -c [file_name] | it prints the number of characters or bytes as mentined |
3 | head -n [file_name] | show the specified number of lines |
4 | head -q [file_name] | don't separate the content of multiple files with a file name tag |
5 | head -v [file_name] | show the file name tag |
6 | head file1 file2 | prints the first 10 lines of each file. |
7 | head --help | Gives all possible variations available in head |
In the below Fig-2 its showing that printing the first 10 lines defaultly when we use head file _name.
Fig-2: head[file_name]
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-1: giphy for head[file_name]
Github link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/head_commands/head.csh
The 'head -c' command counts the number of bytes/characters of a file.
head -c [number] [file _name]
In this Fig-3 it shows the number of bytes or characters which we mentioned .Here each character is considered as one byte and it also considers the spaces and lines as the bytes. so here we used the head -c 60 file_name it considered only 60 characters including spaces and lines too.
Fig-3: head -c <num> [file_name]
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-2: giphy for head -c <num> [file_name]
Github link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/head_commands/head_bytes.csh
The 'head -n' option displays specified number of lines.
head -n [number] [file _name]
In the below Fig-4 we are considering the numbers of lines to be printed as we mentioned. Here i considered head -n8 file_name its prints the only first 8 lines of the file.
Here head -n file _name (or) head -n file _name same.
Fig-4: head -n <num> [file_name]
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-3: giphy for Fig-4: head -n <num> [file_name]
Github link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/head_commands/head_lines.csh
To display the file name before output we use verbose (-v)
head -v [file _name]
In the below Fig-5 we can see the contents with the file _name.Here we have considered head -v file _name command it prints the first 10 lines of the file with the file name.
Fig-5: head -v file_name
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-4: giphy for head -v file_name
Github link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/head_commands/head_verbose.csh
Display the content without the filename.
In Fig-6 we can see the contents without the file name .Here we have considered the 2 files and we used the head -q file1 file2 command it gives us the contents without file name regardlessly as one file.
Fig-6: head -q [file1] [file2]
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-5: giphy for head -q [file1] [file2]
Github link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/head_commands/head_quiet.csh
This command prints the first 10 lines of each file.
In Fig-7 we can see that first 10 lines of each file wih file names.Here we have used the head [file1_name] [file2_name] command so it prints only first 10 lines of the each file.
Fig-7: head [file1_name] [file2_name]
The below GIF shows the whole process from sourcing scripting file till the output.
GIF-6: giphy for head [file1_name] [file2_name]
GitHub link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_BJT/head_commands/head_mutliple.csh
This command is used to display all possible variations of head command.
In the below Fig-8 you can see that by using this command we can see all possible variations of head command.
Fig-8: head --help command
To learn tail command : https://github.com/muneeb-mbytes/linux_course/wiki/11.-tail-command