Linux command
cat 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Example
cat [path/to/file]
Concatenate
cat [file1] [file2] > [output_file]
Append
cat [file1] [file2] >> [output_file]
Number
cat -n [path/to/file]
Example
cat -A [path/to/file]
Example
cat [path/to/file] | [program]
说明
cat (concatenate) reads files sequentially and writes their contents to standard output. It is one of the most frequently used Unix utilities, serving as the standard way to display file contents, combine multiple files, and pipe data to other commands in shell pipelines. When given multiple file arguments, cat concatenates them in order, making it useful for joining split files or appending content. With no file arguments or a dash (-), it reads from standard input, which allows it to function as a simple pass-through in pipelines. Various flags control output formatting, including line numbering and display of non-printing characters.
参数
- -n, --number
- Number all output lines
- -b, --number-nonblank
- Number non-blank output lines only
- -s, --squeeze-blank
- Suppress repeated empty output lines
- -A, --show-all
- Equivalent to -vET; show all characters
- -E, --show-ends
- Display $ at end of each line
- -T, --show-tabs
- Display TAB characters as ^I
- -v, --show-nonprinting
- Use ^ and M- notation for non-printing characters
- -e
- Equivalent to -vE
- -t
- Equivalent to -vT
FAQ
What is the cat command used for?
cat (concatenate) reads files sequentially and writes their contents to standard output. It is one of the most frequently used Unix utilities, serving as the standard way to display file contents, combine multiple files, and pipe data to other commands in shell pipelines. When given multiple file arguments, cat concatenates them in order, making it useful for joining split files or appending content. With no file arguments or a dash (-), it reads from standard input, which allows it to function as a simple pass-through in pipelines. Various flags control output formatting, including line numbering and display of non-printing characters.
How do I run a basic cat example?
Run `cat [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --number do in cat?
Number all output lines