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

Canonical announces new optimized Ubuntu image for Thundercomm RUBIK Pi 3

Ubuntu now runs natively on the Thundercomm RUBIK Pi 3 developer board – a lightweight…

17 hours ago

Introducing Canonical Academy

Validate your skills and advance your career with recognized qualifications from the publishers of Ubuntu…

17 hours ago

🚀 Deploy Poweradmin to Manage PowerDNS on Ubuntu VPS

This article demonstrates how to deploy Poweradmin to manage PowerDNS on Ubuntu VPS server. What…

24 hours ago

Self-Hosting Easypanel and n8n on Ubuntu VPS

This article provides an outline for self-hosting Easypanel and n8n on Ubuntu VPS. What is…

24 hours ago

Introducing silicon-optimized inference snaps

Install a well-known model like DeepSeek R1 or Qwen 2.5 VL with a single command,…

2 days ago

ESWIN Computing launches the EBC7702 Mini-DTX Mainboard with Ubuntu 24.04 LTS

October 23, 2025 – Today, ESWIN Computing and Canonical announced the pre-installation of Ubuntu on…

2 days ago