接下来让我们来看按shell里面的重定向吧
命令如下
command>file 将输出重定向到file
command<file 将输入重定向到file
command>>file 将输出以追加的方式重定向到file
n>file 将文件描述符为n的文件重定向到file
n>>file 将文件描述符为n的文件以追加的方式重定向到file
n>&m 将输出文件m和n合并
n<&m 将输入文件m和n合并
<<tag 将开始标记tag和结束标记tag之间的内容作为输入
文件描述符:0 标准输入 1 标准输出 2 标准错误输出
例子
echo "www.baidu.com" > test
cat test
echo "www.sina.com" >> test
cat test
例子
wc -l test
wc -l < test
两种输出结果不一样 大家练习练习看看
例子
command < infile >outfile
输入和输出重定向同时使用
例子
command 2 > fiile
command 2 >> file
command > file 2>&1
command >> file 2>&1