Linux: Display First Ten Lines (1-10) With Numbers Command

I‘m a new Linux user. I have various text files. I need to show first ten lines of each file. How can I display 1-10 line numbers in Linux or Unix-like system using shell prompt?

You need to use the combinations of the following Linux or Unix-like system commands:

    Tutorial details
    Difficulty Easy (rss)
    Root privileges No
    Requirements None
    Time 1m
  1. sed command
  2. cat command
  3. less command
  4. awk command
  5. mapfile command (Bash v4.x only)

To display 1 to 10 lines from /etc/passwd file and number all output lines, enter:

sed -n "1,10p" /etc/passwd | cat -n

Sample outputs:

Fig.01: Linux/Unix: Bash/KSH SHELL Print nth Line Of a Text File

In this example, print 50-200 lines from demo.txt and number all output lines using less command:
sed -n "50,200p" /etc/passwd | less -N

The following example use the head command to display first 10 lines of /etc/passwd file:

head +10 /etc/passwd | cat -n

Sample outputs:

     1	==> /etc//passwd 

Display 10-20 lines using head and tail combo as follows:

head -20 /etc/group | tail -n 10 | cat -n

Sample outputs:

     1	nobody:*:-2:
     2	nogroup:*:-1:
     3	wheel:*:0:root
     4	daemon:*:1:root
     5	kmem:*:2:root
     6	sys:*:3:root
     7	tty:*:4:root
     8	operator:*:5:root
     9	mail:*:6:_teamsserver
    10	bin:*:7:

🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • aref ghobadi Aug 16, 2015 @ 17:42

    tail command display last ten lines

  • emoye10 Jan 6, 2016 @ 14:23

    it did not for me

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @