Fundamentals 7 min read

10 Essential Linux Commands to Quickly View Text Files

When you need to inspect text files on a Linux system without opening a full editor, these ten command‑line tools—cat, less, head, tail, wc, grep, find, locate, sort, and uniq—provide fast, precise ways to display, search, count, and manipulate file contents.

Liangxu Linux
Liangxu Linux
Liangxu Linux
10 Essential Linux Commands to Quickly View Text Files

cat

The cat command outputs the entire contents of a file to the terminal.

Usage: cat [filename] Example: cat rumenz.com.txt Output:

This is an rumenz.com file.
It contains some random text.

less

The less command displays large text files page by page, preserving formatting and allowing scrolling and searching.

Usage: less [filename] Example: less rumenz.com.txt Output (first screen):

This is an rumenz.com file.
It contains some random text.

--more--

head

The head command shows the beginning of a file, defaulting to the first 10 lines; the number of lines can be changed with -n.

Usage: head [-n number] [filename] Example (first 2 lines): head -n 2 rumenz.com.txt Output:

This is an rumenz.com file.
It contains some random text.

tail

The tail command shows the end of a file, defaulting to the last 10 lines; the number of lines can be changed with -n.

Usage: tail [-n number] [filename] Example (last line): tail -n 1 rumenz.com.txt Output:

It contains some random text.

wc

The wc command counts lines, words, and characters in a file.

Usage: wc [filename] Example: wc rumenz.com.txt Output (lines words characters filename):

2 6 42 rumenz.com.txt

grep

The grep command searches for patterns (regular expressions) within files.

Usage: grep [pattern] [filename] Example (search for "random"): grep "random" rumenz.com.txt Output:

It contains some random text.

find

The find command searches the filesystem for files matching given criteria.

Usage: find [path] -name [pattern] Example (find hosts file): find /etc -name "hosts" Output:

/etc/hosts

locate

The locate command quickly lists all files whose names match a keyword, using a prebuilt database; it is faster than find but not real‑time.

Usage: locate [keyword] Example (search for "hosts"): locate "hosts" Sample output:

/etc/hosts
/usr/share/help/C/filenames/hosts.desktop
/usr/share/help/de/filenames/hosts.desktop
...

sort

The sort command orders the lines of a file alphabetically (or numerically, by date, etc.) and prints the result.

Usage: sort [filename] Example: sort rumenz.com.txt Output:

It contains some random text.
This is an rumenz.com file.

uniq

The uniq command filters out consecutive duplicate lines from a sorted file.

Usage: uniq [filename] Example: uniq rumenz.com.txt Output (duplicates removed):

This is an rumenz.com file.
It contains some random text.

These ten commands form a core toolkit for quickly viewing, searching, and processing text files on Linux, and they can be combined to achieve more powerful text‑handling workflows.

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.

LinuxCommand-lineShell CommandsUnix toolstext-viewingFile Inspection
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.