如何重定向标准输出和标准错误到一个文件中?
时间:2009-05-12 来源:eboowuu
如何重定向标准输出和标准错误到一个文件中?
您可以用几种方法来重定向标准输出和标准错误。
下面有几个例子,列出了在几种场合下如何通过命令行来执行特定的操作:
1、将标准输出重定向到文件:
<command> > <filename>
ls -l > ls-l.txt
2、将标准错误重定向到文件:
<command> 2> <filename>
grep da * 2> grep-errors.txt
3、将标准输出重定向到标准错误:
<command> 1>&2
grep da * 1>&2
4、将标准错误重定向到标准输出:
<command> 2>&1
grep * 2>&1
5、重定向标准错误和标准输出到文件:
<command> &> <filename>
rm -f $(find / -name core) &> /dev/null
相关阅读 更多 +