23 C
Texas
Muhammad Nabeel
Network and System Administrator

how to use Linux head and tail commands

What is Head Command?

head is a program on Unix and Unix-like operating systems used to display the beginning of a text file or piped data.

What is Tail Command?

tail is a program available on Unix, Unix-like systems and FreeDOS used to display the end of a text file or piped data.

How to use Head Command?

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

head /etc/shadow
- Advertisement -

See desired number of lines using head command

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

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

head -n20 /etc/shadow

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

So if you want to see last 20 lines of /etc/shadow file. Then run below command

tail -n20 /etc/shadow

That’s it

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article