Describe:
Standard output refers to the correct information that is returned by the command execution
Standard error output refers to the error message that is returned when the command fails to execute
Linux provides three types of programs I/O Equipment
Standard input (STDIN )- 0 accepts input from the keyboard by default, using < or <<
Standard Output ( STDOUT )- 1 default output to terminal window, default is screen, use > or >>
Standard error Output (STDERR )- 2 default output to terminal window, default is screen, use 2> or 2>>
with I/O redirection, you can Change the default location to output the correct or incorrect information to the screen or file, the input information can be read from the keyboard or file
Programs are made up of instruction + data,and STDOUT and stderr can be redirected to a file
Description:
Format: command action symbol file name
1> to output the correct data to the specified file or device in a overwritten manner
1>> Output The correct data to the specified file or device in an additional way
2> to output the wrong data to the specified file or device in a overwritten manner
2>> to output the wrong data to the specified file or device in an additional way
&> Redirect all output to file
>> on the basis of the original content, additional content
available through # set-c: prevents content from being overwritten by existing files, but can be appended, forced Overrides: >|
# set +c: allow overwrite
[[email protected] ~]# echo "A" > File1[[email protected] ~]# cat File1a[[email protected] ~]# Set-c[[email protected] ~]# echo "123" >file1bash:file1:cannot Overwrite existing file[[email protected] ~]# echo "123" >| File1[[email protected] ~]# cat file1123
[Email protected] ~]$ find/home-name BASHRC > List_right 2> list_error[[email protected] ~]$ cat List_right/hom E/ping/.bashrc[[email protected] ~]$ cat list_errorfind: '/home/user1 ': Permission denied
The standard output and error outputs are directed to different locations:
COMMAND >/path/to/file.out 2>/path/to/error.out
Merge standard output and error output redirect for the same data stream:
&> : Overwrite redirects
&>> : Append redirect
COMMAND >/path/to/file.out 2> &1 (order is important)
COMMAND >>/path/to/file.out 2>> &1
Find/etc-name passwd 2>/dev/null
(): Merging STDOUT of multiple programs
(CAL) > All.txt
[Email protected] ~]$ find/home-name BASHRC 2&>1 list[[email protected] ~]$ find/home-name. BASHRC &> List[[email protected] ~]$ cat listfind: '/home/user1 ': Permission DENIED/HOME/PING/.BASHRC
Standard input: < and <<
Replace the data that was originally to be entered by the keyboard with the contents of the file
Use < to redirect standard input
Use the << stop Word command to redirect multiple lines from the keyboard to stdin
[[email protected] ~]# cat > Catfiletestingcat file test[[email protected] ~]# cat > Catfile < ~/.bashrc[[email p Rotected] ~]# ll catfile ~/.bashrc-rw-r--r--1 root gentoo 235 03:22 catfile-rw-r--r--1 root root 235 Jul 27 20 16/root/.bashr[[email protected] ~]# cat > Catfile << "EOF" > This was a test> OK now stop> eof[[email PR Otected] ~]# cat Catfilethis is a testok now stop
Pipeline command:
Use the symbol "|" to indicate that the command is used to connect
Format: Command 1 | Command 2 | Command 3 | ...
The pipe command only handles standard output and is ignored for standard error output
The pipeline command must be able to accept data from the previous command as standard input to continue processing.
StdErr cannot be piped forward by default and can be implemented with 2>&1 or |&
[Email protected] ~]# Ls-al/etc | Less[[email protected] ~]# lss-al/etc | Less
TR command:
converting and deleting characters
Format:tr [OPTION] ... SET1 [SET2]
-C or--complerment : The complement of the character set
-D or-- Delete : Deletes all characters belonging to the first character set
-S or-squeeze-repeats : The consecutive repeating character is represented by a single character
-T or --truncate-set1 : Converts the corresponding character of the first character set to the corresponding character of the second character set
Example:
1. Convert the contents of the /etc/issue file to uppercase and save to the /tmp/issue.out file
[Email protected] tmp]# Cat/etc/issue | Tr ' A-Z ' A-Z ' >/tmp/issue.out[[email protected] tmp]# cat/tmp/issue.out CENTOS RELEASE 6.8 (FINAL) KERNEL \ r on an \m TTY is \lhostname are \ntime is \ t
2, Each directory of the PATH variable is displayed in a separate row
[Email protected] ~]# echo $PATH | Tr-s ' \ n '/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Conclusion:
the contents of this article is the summary and collation of my class, if there are errors or deficiencies, please pass by the talent of many advice.
The Linux redirection, piping, and TR commands always give