PaRaD1SE

Special Symbols Commonly Used in Linux Shell

Published: 2022/10/22 Views: 1910

Categories: 

Development

A brief summary of the common usage of Linux Shell's pipe character, greater than sign, less than sign and other special symbols

Pipe character ("|")

Use the output of the preceding command as the input of the following command. Multiple commands can be connected using multiple pipe characters.


output redirection character (">")

Redirect the output of the command to a file. Redirection explanation: Generally, the program will output to the standard output stdout, which is usually the terminal being used. The redirection character redirects the standard output to a place other than the standard output.


Append redirection character (">>")

Append the output of the command to a file.


The output of the echo command is one line by default, so there is a newline at the end of the output.

input redirection character ("<")

Take a file as input to the command.


Multi-line input redirector ("<<")

Also known as Here Document, it uses a multi-line string as the input to the command.


Special redirection symbols

Running the program will open the following three files:

Standard input file (stdin)

The file descriptor of stdin is 0, and the program reads data > from stdin by default.

Standard output file (stdout)

The file descriptor of stdout is 1, and the program outputs data > to stdout by default.

Standard error file (stderr)

The file descriptor of stderr is 2, and the program writes error > information to the stderr stream.

Error output redirector ("2>")


Combine standard output and error output (">&")

1>&2 correct return value is passed to 2 output channels &2 means 2 output channels

2>&1 error return value is passed to 1 output channel, &1 means 1 output channel

Be careful not to have spaces between these characters.

Create file structure





Combine output to file ("&>")


Therefore, common commands such as:


It means redirecting both the standard output and error output of the xxx program to the /dev/null file, i.e. discarding the output.

Tags:

Development
Linux
Shell
Bash

Previous

Next