在网上搜索一圈,清楚明了的解释还是 http://www.runoob.com/linux/linux-shell-io-redirections.html
结合理论,整理例子如下:
1、command > file ( >> 不覆盖,追加)
@debian69:~/algoAndSturct$ ls -l > test
@debian69:~/algoAndSturct$ cat test
总用量 384
drwxr-xr-x+ 12 xxx xxx 4096 12月 25 14:41 algo-master
-rw-rwx-w-+ 1 xxx xxx 330396 12月 25 14:47 algo-master.zip
drwxrwx---+ 4 xxx xxx 4096 4月 18 10:59 makefileTest
drwxrwx---+ 11 xxx xxx 4096 4月 25 19:32 selfTest
drwxr-xr-x+ 9 xxx xxx 4096 12月 28 2015 Socket-master
-rw-rwx-w-+ 1 xxx xxx 40204 4月 16 18:13 Socket-master.zip
-rw-rw----+ 1 xxxx xxx 0 4月 26 11:05 test
drwxrwx---+ 4 xxx xxx 4096 4月 24 11:32 UnixProgramTest
2、 command < file
用一个典型的需要输入的命令,wc -l 统计行数
@debian69:~/algoAndSturct$ wc -l < test
9
先输入重定向入参,然后输出重定向到test2
liubowen@debian69:~/algoAndSturct$ wc -l < test > test2
liubowen@debian69:~/algoAndSturct$ cat test2
9
3、stderr 重定向到 file,可以这样写:
command 2 > filecommand 2 >> file (追加)
如果希望将 stdout 和 stderr 合并后重定向到 file,可以这样写:
$ command > file 2>&1 或者 $ command >> file 2>&1