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

Check your desired number of lines using head command

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

-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

Advantech AOM-2721 is now Ubuntu Certified

Canonical announces that the Advantech AOM-2721 is officially joining the list of Ubuntu Certified Hardware.…

6 hours ago

Ruby and Rails Performance Roundup: The Backlog Edition

Yet again instead of tweets, a blog post. The backlog got out of hand -…

6 hours ago

How to Deploy OpenProject on Ubuntu VPS

This article provides a guide demonstrating how to deploy OpenProject on Ubuntu VPS. What is…

6 hours ago

Canonical integrates NVIDIA Nemotron 3.5 Lightning with Ubuntu for always-on AI agents

Canonical is pleased to announce that  NVIDIA’s newly introduced NVIDIA Nemotron 3.5 Lightning, an open,…

2 days ago

Xfwl4’s Second Preview Release

I’m pleased to announce the second preview release of xfwl4, Xfce’s Wayland compositor, version 4.21.1.…

2 days ago

How to Install, Secure, and Set Up MySQL on Ubuntu 26.04 LTS

If you have been using an ecommerce store to place online orders or have been…

3 days ago