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

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

18 hours ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

18 hours ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

18 hours ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

2 days ago

Revolutionizing Web Page Creation: How Structured Content is Slashing Design and Development Time

Co-authored with Julie Muzina A year ago, during our Madrid Engineering Sprint, we challenged ourselves…

3 days ago

Ubuntu Weekly Newsletter Issue 897

Welcome to the Ubuntu Weekly Newsletter, Issue 897 for the week of June 15 –…

3 days ago