Operations 7 min read

Master Essential Linux File Viewing Commands: cat, tac, nl, more, less, head & tail

This guide explains how to use fundamental Linux commands—cat, tac, nl, more, less, head, and tail—to view file contents, display line numbers, navigate pages, and filter output, complete with syntax, options, and practical examples for each tool.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Essential Linux File Viewing Commands: cat, tac, nl, more, less, head & tail

cat

Displays the contents of a file starting from the first line. cat [-AbEnTv] Key options: -A: combines -vET to show non‑printing characters. -b: numbers non‑blank lines only. -E: shows a $ at line ends. -n: numbers all lines, including blanks. -T: displays tabs as ^I. -v: makes other non‑printing characters visible.

[root@www ~]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m

tac

Outputs a file in reverse order, starting from the last line.

tac /etc/issue
Kernel \r on an \m
CentOS release 6.4 (Final)

nl

Numbers the lines of a file. nl [-bnw] file Important options: -b a: number all lines (like cat -n). -b t: omit numbers for blank lines (default). -n ln: left‑justify numbers. -n rn: right‑justify numbers without leading zeros. -n rz: right‑justify numbers with leading zeros. -w: set the width of the number field.

[root@www ~]# nl /etc/issue
     1  CentOS release 6.4 (Final)
     2  Kernel \r on an \m

more

Pages through a file one screenful at a time. more /etc/man_db.config During a more session you can use:

Space: advance one page.

Enter: advance one line. /string: search forward for string. :f: display the current filename and line number. q: quit. b or Ctrl‑b: go back one page (works only on regular files).

less

Similar to more but provides richer navigation. less /etc/man.config Key commands while less is running:

Space or PageDown: forward one page. PageUp: backward one page. /string: search forward for string. ?string: search backward for string. n: repeat the previous forward search. N: repeat the previous search in the opposite direction. q: quit less.

head

Shows the first few lines of a file. head [-n number] file Option: -n number : display the specified number of lines (default is 10).

[root@www ~]# head /etc/man.config
[root@www ~]# head -n 20 /etc/man.config

tail

Shows the last few lines of a file. tail [-n number] file Options: -n number : display the specified number of lines from the end (default is 10). -f: follow the file as it grows; stop with Ctrl‑c.

[root@www ~]# tail /etc/man.config
# (shows last 10 lines)
[root@www ~]# tail -n 20 /etc/man.config
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CATlesstailheadmorenltac
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.