Shell中将标准错误标准输出重定向到同一个文件的两种方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Jerry_1126/article/details/85268936

在Shell中,标准错误写法为 2>, 标准输出为 1> 或者 >。如要要将标准输出和标准错误合二为一,都重定向到同一个文件,可以使用下面两种方式:

方式一: > out.txt 2>&1

[root@localhost ~]# { time ls /etc; } > out.txt  2>&1

方式二: &> out.txt

[root@localhost ~]# { time ls /etc; } &> out.txt

猜你喜欢

转载自blog.csdn.net/Jerry_1126/article/details/85268936