Categories: Ubuntu

How to use Head and Tail command in Linux

What is Head Command?

Head command is used to display first part of files given to its standard output.

What is Tail Command?

Tail is a program available on Unix, Unix-like systems used to display the last number of data of the given input or piped data.

How to use Head Command?

By default head command list first ten lines of a file. In following example I will show you the first Ten lines of /etc/shadow file.

head /etc/shadow
How to use head and tail command in linux 5
Sponsored

Check your desired number of lines using head command

Now, you will see first 15 lines of /etc/shadow file

Sponsored

-n used to define lines.
15 it is number of lines

head -n15 /etc/shadow
How to use head and tail command in linux 6

How to use Tail Command?

Like head command, tail is also display 10 lines by default but these are last 10 lines of a file. use following command to list last lines of a file.

tail /etc/shadow
How to use head and tail command in linux 7

Now if you want to see last 15 lines of /etc/shadow file. Then run following command

tail -n15 /etc/shadow
How to use head and tail command in linux 8

That’s about it!

The post How to use Head and Tail command in Linux appeared first on Osgrove.

Ubuntu Server Admin

Recent Posts

Linux Sed Tutorial: Learn Text Editing with Syntax and Examples

This article was adapted from its original version on NixCraft. Sed is an acronym for…

5 hours ago

How to Fix VMware’s “Could not open /dev/vmmon” Error on Ubuntu

You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…

13 hours ago

How to Fix Ubuntu 404 Errors While Fetching Dependencies

Have you ever found yourself staring at a terminal full of 404 errors while trying…

13 hours ago

How to Fix ‘Please Install All Available Updates’ Error When Upgrading Ubuntu 18.04 to 20.04 LTS

One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …

13 hours ago

How to fix “Release is not valid yet” Error in Docker Containers

In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…

13 hours ago

How to fix “Externally Managed Environment” Pip Errors on Ubuntu

If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…

13 hours ago