Fundamentals 4 min read

Master the Linux cat Command: Options, Syntax, and Real-World Examples

Learn how the Linux cat command concatenates and displays file contents, explore its syntax, permission scope, detailed option flags such as -n, -b, -s, and see practical examples for numbering lines, merging files, clearing files, and creating disk images.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master the Linux cat Command: Options, Syntax, and Real-World Examples

cat command is used to concatenate files and print them to standard output.

Usage permissions

All users

Syntax format

cat [options] fileName

Parameter description

-n or --number : number all output lines starting from 1.

-b or --number-nonblank : number non-blank lines only.

-s or --squeeze-blank : replace multiple consecutive blank lines with a single blank line.

-v or --show-nonprinting : display non-printing characters (except LFD and TAB) using ^ and M- notation.

-E or --show-ends : display $ at end of each line.

-T or --show-tabs : display TAB characters as ^I.

-e : equivalent to -vE.

-A , --show-all : equivalent to -vET.

-t : equivalent to -vT.

Examples

Add line numbers to textfile1 and write to textfile2: cat -n textfile1 > textfile2 Append numbered contents of textfile1 and textfile2 (excluding blank lines) to textfile3: cat -b textfile1 textfile2 >> textfile3 Clear the contents of /etc/test.txt: cat /dev/null > /etc/test.txt Create a floppy disk image from the device: cat /dev/fd0 > OUTFILE Write an image file back to the floppy device: cat IMG_FILE > /dev/fd0 OUTFILE is the name of the output image file.

IMG_FILE is the source image file.

The device capacity must match when writing back.

Commonly used for creating bootable floppy disks.

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.

LinuxShellfile-manipulationcat command
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.