The Linux command obtains the input from the standard input device (stdio) By default, outputting the result to the standard output device (STDOUT) display. In general, the standard input device is the keyboard. The standard output device is the terminal (monitor).
In general, each command will open 3 files when it is run:
- Standard input file (stdin): The stdin file descriptor is 0. Linux programs read data from stdin by default
- Standard output file (stdout): The stdout file descriptor is 1. Linux programs more stdout output data.
- Standard error file (stderr): The file descriptor for stderr is 2. The Linux program writes an error message to the stderr stream.
Output Redirection
/dev/null File
/dev/null is a special file, and content written to it will be discarded.
Example:
$Date>Date. txt#将date命令的结果重定向到文件date. txt$ ll >>Date. txt#将ll命令的结果追加到文件date. txt$ Cat <Date. txt#将cat命令的输入重定向到文件date. txt. (The contents of the file Date.txt as the cat parameters)$ Cat <Date. txt >date2.txtREDIRECT content #将文件date. txt to file Date2.txt$ cat <<EOF #将从键盘输入的字符串打印到显示器 until EOF is entered$./test2>result. txt#将执行脚本test的错误信息重定向到文件result$./test >>result. txt2>&1 #将执行脚本test的错误信息和输出信息以追加的方式重定向到文件result. txt
Linux IO redirection