1. 输出重定向:
默认条件下,标准输出和错误输出都是终端,可以把标准输出和错误内容进行重定向:
[~]# echo "hello\!"
hello\!
[~]# echo "hello!"
-bash: !": event not found "
把标准输出重定向到文件
[~]# echo "hello" > test.sh
[~]# cat test.sh
hello
'>'输出方式默认等价'1>'
[~]# echo "hello" 1> test.sh
[~]# cat test.sh
hello
但是错误内容还是会显示在屏幕上:
[~]$cat edit.sql /root/test.sh > temp.sh
cat: /root/test.sh: Permission denied
可以把错误内容也输出到文件中(利用文件描述符):
[~]$cat edit.sql /root/test.sh 1> temp.sh 2> error.sh
[~]$cat temp.sh
select dbms_rowid.rowid_object('AAAZdQAAGAAATxjAAk') data_object_id#,
dbms_rowid.rowid_relative_fno('AAAZdQAAGAAATxjAAk') rfile#,
dbms_rowid.rowid_block_number('AAAZdQAAG