Linux: management of file input and output

1. Definition of input and output

1 Input: It is our keyboard, mouse and the characters we use to enter in the system

2 Output: After the system receives the function characters we want to implement, the characters are processed and produced by the system. There will be two kinds of input: the number 1 is the correct output, the number 2 is the error output, by default both outputs will be directed to the character device by the system

2. How to manage output

1. Non-interactive multi-line entry

vim C_pass.sh
passwd 

sh C_pass.sh

does not run automatically

passwd <<EOF
chcshidewu
dhwjefffe
EOF
sh C_pass.sh

Can run automatically to avoid interaction



2. How to manage output redirection

>            redirect correct output
2 >    redirect error output
&>    redirect all output

2>&1 converts the error output number from 2 to 1

Do the following experiments with the student user

find /etc/ -name passwd > file.out
find /etc/ -name passwd 2> file.out
find /etc/ -name passwd &> file.all
find /etc/ -name passwd > file 2>&1
"Note: Slave orientation will overwrite the original file content!!!"
vim westos
hello westos
find /etc/ -name passwd > westos

The content of the original file of cat westos is gone



3. Append: Append the output to the file while keeping the contents of the original file unchanged

>>             append to correct output
2 >>    append to error output

&>>    append to all outputs

find /etc/ -name passwd >> westos
find /etc -name passwd 2>> westos

find /etc -name passwd &>> westos



4. Pipeline: The input pipeline that turns the output into the next program is used to combine multiple commands.

ls /bin | wc -l
"Note: The output will become input after passing through the pipeline, so it cannot be saved in the file"
tee ##Copy the output to the specified location

ls /bin | tee file | wc -l

The output has been saved in cat file ##file



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325405646&siteId=291194637