1: Standard input and output.
device | Device file name | File descriptor | Types of |
keyboard | /dev/stdin | 0 | Standard input |
monitor | /dev/stdout | 1 | Standard output |
monitor | /dev/stderr | 2 | Standard error output |
2: Output redirection (meaning that it should have been output to the monitor, now output to a file): the purpose is to facilitate management, but these commands must be output
Types of | symbol | effect |
---|---|---|
Standard output redirection | Command> File | Overwritten method, output the correct command to the specified file or device |
Command >> File | Append the correct output of the command to the specified file or device by appending | |
Standard error output redirection | Error Command 2> File | Overwrite the way, output the error of the command to the specified file or device |
Error command 2 >> file (no space between 2 and>) | In addition, output the error of the command to the specified file or device. |
Then use ls> abc
You will find that the new one will overwrite the old one. This is the difference between append and overwrite.
Correct output and wrong output are saved at the same time | Command> File 2> & 1 | Overwritten method, save correct output and wrong output in the same file |
Command >> File 2> & 1 | Added way to save correct output and wrong output in the same file | |
Command &> File | Overwritten method, save correct output and wrong output in the same file | |
Command & >> File | Added way to save correct output and wrong output in the same file | |
Command >> File 1 2 >> File 2 | Append the correct output to file 1, and the wrong output to file 2. |
3: Input redirection
wc [options] [file name]
Options: -c count bytes
-w count words
-l count lines
After input, use ctrl + d to indicate that 4 lines of 4 words and 24 characters (including carriage return) are entered.
wc <filename
wc << character (end with the same character at the second occurrence)