cat Command

Purpose

Concatenates and displays files in a restricted environment.

Syntax

cat [ -A ] [ -b ] [ -e ] [ -E ] [ -n ] [ -s ] [ -t ] [ -T ] [ -u ] [ -v ] [ File ... ]

Description

The cat command reads one or more files and writes their contents to standard output.

In restricted environments, certain options and paths are blocked for security reasons. Options that contain the letters p or P are explicitly not allowed. Also, redirecting the output by using > or >> character is not allowed.

Flags

Table 1. Flags
Item Description
-A Displays all the contents of a file. The -A flag includes all the nonprinting characters in the display. This option is equivalent to -vET flag.
-b Numbers all the nonblank lines in a file and displays the output. The blank lines are not numbered. If both the -b and -n flags are used, the -b flag overrides the output of -n flag.
-e Adds a $ (dollar sign) at the end of each line, including the blank lines, and displays the output. Also, this option displays all the nonprinting characters. This option is equivalent to -vE flag.
-E Adds a $ (dollar sign) at the end of each line, including the blank lines and displays the output.
-n Numbers all the lines in a file, including the black lines and displays the output.
-s Squeezes multiple adjacent blank lines in a file into a single blank line and displays the output.
-t Display the tab characters in a text file as ^I. Also, this option displays all the nonprinting characters except the end of a line. This option is equivalent to -vT flag.
-T Display the tab characters in a text file as ^I.
-u Uses unbuffered I/O for both reading and writing.
-v Displays nonprinting characters except tab, newline, and form feed.

Examples

  1. To view the content of a file, enter the following command:
    cat <File_name>
  2. To view the contents of multiple files in sequence, enter the following command:
    cat <File1> <File2>

    The output appears on screen. Redirecting the output to a new file by using > is not allowed.

  3. To number all the lines in a file, enter the following command:
    cat -n <File_name>
  4. To display nonprinting characters and line endings, enter the following command:
    cat -A <File_name>
  5. To read a specific content from the standard output, enter the following command:
    echo "<content>" | cat -