Fundamentals 9 min read

Master Linux Text Viewing: Essential Commands and Practical Tips

This guide introduces the most useful Linux text‑viewing commands—including cat, tac, more, less, head, tail, sort, sed, uniq, and vi—explaining their basic syntax, common options, and practical examples for efficient file inspection and manipulation.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Text Viewing: Essential Commands and Practical Tips

Full‑text display with cat

The cat command outputs an entire file to the terminal. Basic usage:

cat file               # display full content
cat -n file            # display with line numbers

It can also concatenate files:

cat file1 file2 >file3   # merge file1 and file2 into file3

Reverse display with tac

tac

is cat reversed; it prints a file line‑by‑line in reverse order.

tac file

Paginated view with more

more

shows a file page by page, useful for large files. more file Common navigation keys:

Enter – scroll down one line (default)

Space – scroll down one screen

b – scroll up one screen

= – display current line number

:f – show file name and line number

q – quit

Start from a specific line: more +10 file # start display at line 10 Start from a matching string:

more +/string file   # start two lines before the line containing "string"

Interactive browsing with less

less

provides forward and backward navigation, plus powerful search.

less file          # view file
less -N file       # view with line numbers
less -m file       # view with percentage progress

Key bindings:

f – forward one screen

b – backward one screen

Enter or j – forward one line

k – backward one line

G – go to the last line

g – go to the first line

/string – search forward for "string"

?string – search backward for "string"

q – quit

Switch between multiple files:

less file1 file2 file3
:n   # next file
:p   # previous file
:x   # first file
:d   # remove current file from the list

Show file header with head

head

displays the beginning of a file.

head -n 100 file   # first 100 lines
head -n -100 file # all but the last 100 lines

Show file tail with tail

tail

displays the end of a file and can follow updates.

tail -100 file          # last 100 lines
tail -n +100 file       # from line 100 onward
tail -f logFile         # continuously display new lines as the file grows

Sorted display with sort

sort

orders lines in a file. Examples:

# Ascending (default)
sort test.txt
# Descending
sort -r test.txt
# Remove duplicate lines
sort -u test.txt
# Numeric sort
sort -n file

Use -r for reverse order, -u to drop duplicates, and -n for numeric comparison.

Filtering with sed

sed

is a stream editor; here we show only viewing‑related features.

# Print lines containing a keyword
sed -n "/string/p" logFile
# Print specific line ranges
sed -n "1,5p" logFile          # lines 1‑5
sed -n "'3,5{=;p}'" logFile   # lines 3‑5 with line numbers
sed -n "10p" logFile           # line 10 only

Remove duplicate lines with uniq

uniq

filters adjacent duplicate lines.

uniq file               # drop duplicate lines
uniq -c file            # show duplicate count
uniq -d file            # only duplicated lines
uniq -u file            # only unique lines
uniq -i file            # ignore case
uniq -w 10 file         # compare first 10 characters

Quick file view with vi

Open a file in the classic editor: vi file For more powerful editing, consider vim, which extends vi with many features (not covered here).

Conclusion

Linux offers a rich set of text‑viewing utilities. Choose the command that matches your workflow—simple display with cat, paginated browsing with more or less, selective extraction with head / tail, sorting with sort, filtering with sed, deduplication with uniq, or quick editing with vi. For deeper options, consult the manual pages.

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.

LinuxCATCommand-linelesssedsorttext-viewing
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.