10 Essential Linux Commands for Quickly Viewing Text Files
This guide introduces ten commonly used Linux command‑line tools—cat, less, head, tail, wc, grep, find, locate, sort, and uniq—explaining their purpose, basic syntax, and practical examples for efficiently inspecting and processing text files.
When you need to inspect text files on a Linux system without opening a full‑featured editor, command‑line utilities provide fast and precise ways to view content. Below are ten widely used commands, each with a brief description, usage syntax, and example output.
cat
The cat command reads a file and prints its contents to the terminal.
Usage: cat [filename] Example: cat rumenz.com.txt Output:
This is an rumenz.com file.
It contains some random text.less
lessdisplays large 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
headshows 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: head -n 2 rumenz.com.txt Output:
This is an rumenz.com file.
It contains some random text.tail
tailshows the end of a file, also defaulting to 10 lines and configurable with -n.
Usage: tail [-n number] [filename] Example: tail -n 1 rumenz.com.txt Output:
It contains some random text.wc
wccounts lines, words, and bytes in a file.
Usage: wc [filename] Example: wc rumenz.com.txt Output:
2 6 42 rumenz.com.txtgrep
grepsearches for patterns (including regular expressions) within files.
Usage: grep [pattern] [filename] Example: grep "random" rumenz.com.txt Output:
It contains some random text.find
findlocates files in a directory hierarchy that match given criteria.
Usage: find [path] -name [pattern] Example: find /etc -name "hosts" Output:
/etc/hostslocate
locatequickly finds files by name using a prebuilt database, faster than find but not real‑time.
Usage: locate [keyword] Example: locate "hosts" Sample output includes multiple paths containing "hosts".
sort
sortorders the lines of a file alphabetically, numerically, or by date.
Usage: sort [filename] Example: sort rumenz.com.txt Output:
It contains some random text.
This is an rumenz.com file.uniq
uniqfilters out consecutive duplicate lines, outputting only unique entries.
Usage: uniq [filename] Example: uniq rumenz.com.txt Output:
This is an rumenz.com file.
It contains some random text.These ten commands enable rapid viewing, searching, and basic processing of text files on Linux, and they can be combined for more powerful workflows.
Signed-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.
