TrumanWong

cat

Concatenate multiple files and print to standard output.

Summary

cat [OPTION]... [FILE]...

The main purpose

  • Display the contents of the file, or read standard input if there is no file or the file is -.
  • Concatenate the contents of multiple files and print to standard output.
  • Display invisible characters (control characters, newlines, tabs, etc.) in the file content.

Parameters

FILE (optional): The file to be processed, which can be one or more.

Options

Long options are equivalent to short options

-A, --show-all Equivalent to the "-vET" combination option.
-b, --number-nonblank Only number non-blank lines, starting from 1, overriding the "-n" option.
-e is equivalent to the "-vE" combination option.
-E, --show-ends Display '$' characters at the end of each line.
-n, --number Number all lines, starting from 1.
-s, --squeeze-blank Squeeze consecutive blank lines into one line.
-t is equivalent to the "-vT" combination option.
-T, --show-tabs Use "^I" for TAB (tab character).
-u POSIX compatibility option, meaningless.
-v, --show-nonprinting Use "^" and "M-" symbols to display control characters, except LFD (line feed, that is, newline character '\n') and TAB (tab character).

--help Display help information and exit.
--version Display version information and exit.

return value

The return status is success unless illegal options or illegal parameters are given.

example

# Combine and display multiple files
cat ./1.log ./2.log ./3.log
# Display non-printing characters, tabs, and newlines in the file
cat -A test.log
# Blank lines in compressed files
cat -s test.log
# Display the file and append line numbers to the beginning of all lines
cat -n test.log
# Display the file and append line numbers to the beginning of all non-blank lines
cat -b test.log
# Display the contents of standard input and the contents of the file together
echo '######' |cat - test.log

Notice

  1. This command is a command in the GNU coreutils package. For related help information, please view man -s 1 cat or info coreutils 'cat invocation'.
  2. When using the cat command to view larger files, the text flashes across the screen quickly (scrolls), and the user often cannot see the displayed content clearly. To control the scrolling, press Ctrl+ Press the s key to stop scrolling; press the Ctrl+q key to resume scrolling; press the Ctrl+c (interrupt) key to terminate the execution of the command and return to the Shell prompt state.
  3. It is recommended that you use less, more commands or text editors such as emacs and vi when viewing larger files.

Reference link

  1. Question about LFD key