shell advanced techniques - Redirection

The following list is supported Shell redirection operator.

Operators Features
< Redirect input
> Redirecting output
>> Additional output
2> Redirect error
&> Redirect output and errors
>& Redirect output and errors
2>&1 Redirected to the standard error output
1>&2 Redirecting standard output to the error
>| When redirecting output options covering noclobber
    #find命令将搜索结果输出到foundit文件,把错误信息输出到/dev/null
    [root@xieqichao ~]# find . -name "*.c" -print > foundit 2> /dev/null
    #将find命令的搜索结果和错误信息均输出到foundit文件中。
    [root@xieqichao ~]# find . -name "*.c" -print >& foundit
    #同上。
    [root@xieqichao ~]# find . -name "*.c" -print > foundit 2>&1
    #echo命令先将错误输出到errfile,再把信息发送到标准错误,该信息标准错误与标准输出合并在一起(errfile中)[root@xieqichao ~]# echo "File needs an argument" 2> errfile 1>&2
    [root@xieqichao ~]# cat errfile
    File needs an argument
Published 350 original articles · won praise 52 · views 30000 +

Guess you like

Origin blog.csdn.net/xie_qi_chao/article/details/105039031