Bootstrap

【shell】linux输出重定向|输出重定向2>&1

目录

即看即用

详细

知识铺垫

说明

【shell】输出重定向2>&1


即看即用

标准输出:

 ls thereisno 1> out.txt  标准输出重定向  也可以不加1写成 ls thereisno > out.txt

标准错误:

 ls thereisno 2> out.txt  标准错误重定向

错误:

 ls thereisno > out.txt  2>&1  把错误定向到标准输出,然后统一重定向

 所有IO:

ls thereisno &> out.txt  所有IO重定向(&>中的&可以代表任意,0,1,2,3……)

详细

标准输出(stdout)和标准错误(stderr),Stdout的编号为1,stderr的编号为2。

默认情况下,重定向操作符(如>|<)仅适用于stdout的编号1,(service --status-all |& grep network,|&将stdout和stderr一起输送到右侧标准输入(stdin)流上的进程)

操作符>重定向,将stderr(编号为2)输出定向到Stdout(编号为1),使用descriptor重定向到其他流,需要在其前面加

;