Funnel Family output redirection
Enter the correct command result into the file.
Notice:echo -- display a line of text
>>
Append redirect, append to last row.
[[email protected] fangqihan]# cat 1.txt haha[[email protected] fangqihan]# echo 'hello linux' >> 1.txt [[email protected] fangqihan]# cat 1.txt hahahello linux
2>>
Only the wrong command results are entered into the file
[[email protected] fangqihan]# asas 'wewe' >> 1.txt -bash: asas: 未找到命令[[email protected] fangqihan]# cat 1.txt hahahello linux[[email protected] fangqihan]# asas 'wewe' 2>> 1.txt [[email protected] fangqihan]# cat 1.txt hahahello linux-bash: asas: 未找到命令
&>>
The results of the command return are entered into the file, whether the command is correct or not.
[[email protected] fangqihan]# echo 'wewe' &>> 1.txt [[email protected] fangqihan]# cat 1.txt hahahello linux-bash: asas: 未找到命令wewe
Method 2:
commands >>3.txt 2>>3.txt
>
Standard redirection, empty first, then write content.
[[email protected] fangqihan]# cat 1.txt abcd[[email protected] fangqihan]# echo 'hello linux' > 1.txt [[email protected] fangqihan]# cat 1.txt hello linuxset -C # 开启防止标准重定向功能,无法覆盖已存在的文件 [[email protected] fangqihan]# echo 'haha' > 1.txt -bash: 1.txt: 无法覆盖已存在的文件set +C # 关闭此功能
Input redirect
Notice:tr -- translate or delete characters
<
Get input from a file
[[email protected] fangqihan]# cat 1.txt hahahello linux-bash: asas: 未找到命令wewe[[email protected] fangqihan]# tr 'a-z' 'A-Z' < 1.txt HAHAHELLO LINUX-BASH: ASAS: 未找到命令WEWE
<<
<<
: Here is the document that is generated here, with cat >> 1.txt << EOF
multiple rows appended.
Pipeline |
The output of the command before the pipeline is treated as an input to the latter command.
# example 1:对给定的字符串进行小写转换成大写字母[[email protected] ~]# echo hello linux |tr a-z A-Z HELLO LINUX# example 2:取出文件内容并将小写字母转换成大写展示出来[[email protected] ~]# cat 1.txt huckENDabc[[email protected] ~]# cat 1.txt | tr a-z A-ZHUCKENDABC# example 3:取出文件中的第3-4行的内容[[email protected] ~]# cat -n 1.txt 1 huck 2 END 3 a 4 b 5 c[[email protected] ~]# head -4 1.txt |tail -2ab
|tee
: read from standard input and write to standard output and files
[[email protected] ~]# echo hi,my name is ham |tee 2.txthi,my name is ham
Linux (6), Funnel Family & pipelines