Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Shell redirection

Shulou Source: shulou.com Published: 2022-06-01 04:57:34 10月02日 Update

There are three files opened by the system under Liunx, namely, standard input, dimension output and standard error output. The user's shell sets the keyboard as the default standard input, and the default standard input and standard error output as the screen. That is, the user enters commands from the keyboard and then inputs the results and error messages to the screen

The so-called redirection is not applicable to the system default dimension input / input, but redirection, so the redirection is divided into input redirection, input redirection and error output redirection. To achieve redirection, you need to know the redirection operator, and shell determines the redirection operation based on the redirection operator.

(1) enter the redirection operators''and' > >'

Output redirection does not output the output of the command on the screen, but to a specified file.

Output redirection is used a lot under Linux. For example, if the output of a command is so long that a screen cannot be displayed, you can specify the output of the command to a file, and then use the more command to view the file to get the complete information of the output of the command.

This command outputs all the system running process information output from ps-ef to the ps.txt file instead of to the screen. You can use the more command to view the information processes running by the system in the ps.txt file.

Note: if the file specified after'> 'does not exist, shell will automatically rebuild one; if the file exists, the original contents of the file will be overwritten; if you do not want to overwrite the existing file, you can use the' > > 'operator.

This command appends all file information in the / etc directory and its subdirectories to the end of the / root/install.log file. The original contents of the / root/install.log file still exist.

(3) error redirection operator'2 >'2 > >'

Error redirection is the same as marking output redirection. Redirection of error output

Where tar is the package name command, you can see the decompression process of tar on the screen. If 'text.tar.gz' is a corrupted compressed package, the error message will be output to the errot.txt file.

Tags: Input command output file content operator error screen standard information system separator keyboard delimiter character that is message user result but Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Shulou Tech Info Shulou Technology Docker