Fundamentals 9 min read

Master Linux File Viewing: cat, tac, head, tail, more & less Explained

This guide walks through the most common Linux file‑viewing commands—cat, tac, head, tail, more, and less—detailing their purpose, syntax, useful options, arguments, and practical examples to help you navigate and inspect file contents efficiently.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux File Viewing: cat, tac, head, tail, more & less Explained

1. cat command

1. File handling

cat concatenates files and prints them to standard output, frequently used to display file contents, similar to the Windows type command.

Note: When a file is large, the output scrolls quickly; use more for paging. Press Ctrl+S to pause scrolling and Ctrl+Q to resume. Press Ctrl+C to abort the command.

2. Syntax

cat [options] (arguments)

3. Options

-n or --number: number all output lines starting at 1
-b or --number-nonblank: number only non‑blank lines
-s or --squeeze-blank: replace multiple consecutive blank lines with a single blank line
-A: display non‑printable characters and show "$" at line end
-e: equivalent to -vE
-t: equivalent to -vT

4. Arguments

File list: specify the files to concatenate.

5. Examples

cat m1               # display the contents of file m1
cat m1 m2            # display the contents of m1 and m2 sequentially
cat m1 m2 > file     # concatenate m1 and m2 and write the result to file

2. tac command

tac outputs a file in reverse order, showing the last line first and the first line last.

1. Syntax

tac [options] (arguments)

2. Options

-a or --append: append content to the end of a file
-i or --ignore-interrupts: ignore interrupt signals

3. Arguments

File list: specify the files whose content should be reversed.

4. Example

tac file

3. head command

head displays the beginning of a file; by default it shows the first 10 lines.

1. Syntax

head [options] (arguments)

2. Options

-n<N>: show the first N lines
-c<N>: show the first N bytes
-v: always display the file name header
-q: never display the file name header

3. Arguments

File list: specify the files whose head should be shown.

4. Example

head -n 3 file   # display the first 3 lines of file

4. tail command

tail displays the end of a file; by default it shows the last 10 lines. It can also start from a specific line or byte offset.

1. Syntax

tail [options] (arguments)

2. Options

-n<N>: output the last N lines
-c<N>: output the last N bytes
--help: show help information
--version: show version information

3. Arguments

File list: specify the files whose tail should be shown.

4. Examples

tail file                     # show the last 10 lines of file
tail -n +10 file              # show file from line 10 to the end
tail -c 10 file               # show the last 10 bytes of file

5. more command

more paginates output, displaying one screen at a time and showing a progress prompt such as "--More--(35%)".

1. Common key bindings

Space: display the next screen

Enter: display the next line

H: show help screen

B: display the previous screen

Q: quit more

2. Syntax

more [options] (arguments)

3. Options

-<number>: set the number of lines per screen
-d: display "--More--(xx%)[Press space to continue, 'q' to quit.]"
-c: refresh the screen without scrolling
-s: squeeze multiple blank lines into one
-u: suppress underlining
+<number>: start displaying from the specified line number

4. Argument

File: specify the file to be paginated.

5. Examples

more -dc file          # clear screen before showing file and display progress percentage
more -c -10 file       # clear screen and show 10 lines per screen

6. less command

less provides similar functionality to more but allows both forward and backward navigation, making it suitable for large files.

1. Syntax

less [options] (arguments)

2. Options

-e: automatically exit when the end of the file is reached
-f: force opening of non‑regular files
-g: suppress highlighting of all matches to speed up display
-N: show line numbers at the beginning of each line
-s: squeeze multiple blank lines into one
-S: truncate long lines rather than wrapping them
-x<N>: display TAB characters as N spaces

3. Argument

File: specify the file to be viewed.

4. Example

less file
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.

LinuxCATtailFile Viewinghead
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.