standard input and output redirection-- any command executed under Linux will go through the process shown:
Directory
Three types of I/O devices
Redirect I/O to a file
Tr
Using the Pipe link command
Practical cases
I. I/O devices
Standard input (STDIN)-0 accepts input from the keyboard by default
Standard output (STDOUT)-1 Default output to terminal window
Standard error (STDERR)-2 default output to terminal window
1> or > correct output to file
2> error Output to file
> cover
2>> Append
file exists:> and >> can create new file
file does not exist:> overwrite >> append
set-c is forbidden, but can be appended
>|+ file name Force Overwrite
Set +c Allow overwrite
&> All output Files
2>&1 Turn the wrong into the right
1>&2 Turn the right into the wrong
() merging output from multiple programs
Example: (Cal 2007;cal) > All.text
For example:
tr ABCD 123 converts a conversion of A to 1,b to 2,CD to 3
TR ABC 1234 converts a to 1,b converted to 2,c to 3, 4 invalid
tr-t ABCD 123 will a->1,b->2,c->3,d invalid
tr-d A removes the A string
echo Hello 123 World | tr-cd 0-9 only leaves the 0-9, Deleting all characters in the input text that are not in the complement (a bit around) /c16>
Run results
tr-s ab converts multiple consecutive A and b into a and B
TR A [:p UNCT:] will error
tr-d Abd </etc/fstab Delete any of the ABC characters in the Fstab file
cat > File then enter the content, Ctrl+d left in a disguised form of an input
cat > File3.txt </etc/fstab Copy the contents of Fstab to File3.txt
Video 56.03 screenshot
cat > File4.txt << EOF
Video Screen 57.19 screenshot
can take advantage 2>&1 | error results can also be passed to the pipeline
Less paging to view output
ls-l/etc |
mail-s "subject" + username --e-mail sent to the specified user
User Lisi send the subject as test, the content is Hello World mail to the user Zhanshan, the result diagram is as follows:
Combined with pipe breaks:
echo Hello World | mail-s "Test" +username
1. Convert the contents of the/etc/issue file to uppercase and save to the/tmp/issue.out file
cat/etc/issue |tr A-z >/tmp/issue.out
TR A-Z </etc/issue >/tmp/issue.out
2. Convert the current system login user's information to uppercase and save to the/tmp/who.out file
W.H.O. | tr [A-z] [a-z] >/tmp/who.out
3, a Linux user to the root email, request the message titled "Help", the message body is as follows:
Hello, I am Username, the system version is Here,please help me to Check it, thanks+ operating system version information
ECHO-E hello,i am ' whoami ', the system version is Here,please help me to check it,thanks. " \ n "' Cat/etc/redhat-release ' | Mail-s Help Root
4, the/root/file list, displayed as a line, and the file name separated by a space
Ls-1/root/|tr "\ n" ""
5. Calculation 1+2+3+. The sum of +99+100
echo {1..100} |tr "" + |BC
6, processing string "Xt.,l 1 jr#! $mn 2 c*/fe 3 uz 4", keep only the numbers and Spaces
echo "Xt.,l 1 jr#hat-releasemn 2 c*/fe 3 uz 4" | TR-CD [:d Igit:][:blank:]
7. Display the path variable in a separate row for each directory
echo $PATH |tr: "\ n"
Linux Learning-standard input and output