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

在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

This entry was posted in LinuxBasic and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *