Get the App
SLTechnology News&Howtos  ›  Servers  › 

Detailed instructions on the use of Linux input and output redirection

Shulou Source: shulou.com Published: 2022-06-02 00:58:22 10月02日 Update

1. Linux standard input and output

Linux standard input and output devices are mainly keyboards and monitors, as shown in the following table.

Note: one of the > means: overwrite the contents of the original file; if the file does not exist, create the file; if the file exists, empty it; usually when we back up and clean up the log file

Two > that is > > means: after the content in the original file is appended; if the file does not exist, the file is created; if the file exists, the new content is appended to the end of that file, and the original content in the file is not affected.

2. Linux output redirection

Output redirection: change the input source and output location of the program.

The main applicable methods are shown in the following table:

Output redirection type symbol function standard output redirection command > file overwrite, output the correct output of the command to the specified file or device command > > file by append, output the correct output of the command to the specified file or device standard error output redirection error command 2 > file overwrite Output the error output of the command to the specified file or device in the error command 2 > > file by append, output the error output of the command to the specified file or device and save the command > file 2 > & 1 to overwrite, save the correct output and error output of the command to the same file command > file 2 > & 1 as an append Save the correct output and error output of the command to the same file. The command & > file overwrites the correct output and error output of the command to the same file. Save the correct output and error output of the command to the same file. Save the correct output and error output of the command to the same file. Command > File 12 > File 2 as an append Save the correct output of the command in file 1 Save the error output of the command to file 2 in override mode

3. Linux input redirection

Enter redirect type symbol function standard input command

Tags: File output command content input standard error mode device monitor identity identifier symbol type keyboard function screen point two location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple Redmi Microsoft OPPO Reno