Easy Tutorial
❮ Linux Comm Rgrep Linux Comm Ed ❯

Linux cat Command

Linux Command Manual

The cat (short for "concatenate") command is used to concatenate files and print them to the standard output device.

User Permissions

All users

Syntax

cat [-AbeEnstTuv] [--help] [--version] fileName

Parameter Description:

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

-b or --number-nonblank: Similar to -n, but does not number blank lines.

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

-v or --show-nonprinting: Uses ^ and M- notation, except for LFD and TAB.

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

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

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

-e: Equivalent to "-vE" option;

-t: Equivalent to "-vT" option;

Examples:

Add line numbers to the content of textfile1 and output it to textfile2:

cat -n textfile1 > textfile2

Add line numbers (excluding blank lines) to the content of textfile1 and textfile2, then append it to textfile3:

cat -b textfile1 textfile2 >> textfile3

Empty the contents of the /etc/test.txt file:

cat /dev/null > /etc/test.txt

The cat command can also be used to create image files. For example, to create a floppy disk image file, insert the floppy disk and enter:

cat /dev/fd0 > OUTFILE

Conversely, to write an image file to a floppy disk, enter:

cat IMG_FILE > /dev/fd0

Note:

Linux Command Manual

❮ Linux Comm Rgrep Linux Comm Ed ❯