πŸ“‘Linux/Unix: File Viewing, Redirection & Filters
Estimated reading: 3 minutes 283 views

Linux/Unix: Viewing Tools – cat, less, more, head, tail, tac Explained

Introduction – Why Learn Linux File Viewing Tools?

When working on Linux/Unix systems, it’s essential to view, inspect, and analyze text files directly from the terminal. Tools like cat, less, more, head, tail, and tac allow you to do this efficiently without needing a GUI-based editor.

In this guide, you’ll learn:

  • The role of each command in viewing file content
  • Syntax, usage, and practical examples
  • How to scroll, filter, or reverse-read logs and large files

cat – Concatenate and Display File Content

Syntax:

cat [options] filename

Description:

  • Displays the full contents of a file on standard output.
  • Good for small files or quick previews.

Examples:

cat file.txt              # View entire file
cat file1 file2 > merged  # Combine files into one

Use cat -n to show line numbers:

cat -n file.txt

less – Scrollable File Viewer (Recommended)

Syntax:

less filename

Description:

  • Opens file in a scrollable viewer.
  • Supports forward and backward navigation.
  • Does not load entire file into memory, making it ideal for large files.

Navigation Tips:

KeyAction
↑/↓Scroll line up/down
SpacePage down
bPage up
/patternSearch forward
qQuit viewer

more – Basic Pager

Syntax:

more filename

Description:

  • Displays file page-by-page from top to bottom.
  • Less powerful than less, but widely available.

Example:

more largefile.txt

Press q to exit, Space for next page.


🧒 head – View the Top of a File

Syntax:

head [options] filename

Description:

  • Shows the first 10 lines by default.

Examples:

head file.txt               # First 10 lines
head -n 20 file.txt         # First 20 lines

Useful for config or log previews.


πŸ‘£ tail – View the Bottom of a File

Syntax:

tail [options] filename

Description:

  • Displays the last 10 lines by default.
  • Can follow file updates in real-time (like log monitoring).

Examples:

tail file.txt               # Last 10 lines
tail -n 25 file.txt         # Last 25 lines
tail -f /var/log/syslog     # Real-time log updates

Combine with grep for filtered monitoring:

tail -f logfile.log | grep "ERROR"

tac – Display File in Reverse

Syntax:

tac filename

Description:

  • Displays the file line-by-line in reverse order (bottom to top).
  • Great for reading logs or reversed sequences.

Example:

tac error.log

Summary – Recap & Next Steps

Each of these tools provides a fast, memory-efficient way to explore file content from the terminal. From quick views (cat) to advanced paging (less) and log monitoring (tail -f), these commands form the backbone of Linux file inspection.

Key Takeaways:

  • Use cat for quick views, less for scrollable output.
  • head and tail are great for peeking at the top or bottom of files.
  • tac shows content in reverse, useful for logs and debugging.
  • less is preferred for large files and supports searching.

FAQs

When should I use less instead of cat?
Use less for large filesβ€”it allows paging and doesn’t flood your terminal.

How can I monitor real-time logs in Linux?
Use:

tail -f /path/to/logfile

What’s the difference between more and less?
less allows both forward/backward scrolling and searching; more only pages forward.

Can tac be used on binary files?
No. It’s designed for reversing line-based text files, not binaries.

How do I view only the first 5 lines of a file?
Use:

head -n 5 filename

Share Now :
Share

πŸ”΅ Linux/Unix: Viewing Tools (cat, less, more, head, tail, tac)

Or Copy Link

CONTENTS
Scroll to Top