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.
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 \mtac
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 \mmore
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.configtail
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.configSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
