Shell之StdI/O和Pipe
Shell之StdI/O和Pipe
😄 Written by Zak Zhu
学习python风格, 优雅规范书写shell代码
参考
- RHCE培训(RH033/unit-7)
- archoncap/Linux CAT与ECHO命令详解(https://www.cnblogs.com/archoncap/p/6080088.html)
StdI/O重定向
| 操作 | 注释 |
|---|---|
| > | Overwrite |
| 1> | Redirect STDOUT to file |
| 2> | Redirect STDERR to file |
| &> | Redirect all output to file |
| >> | Append |
| 1>> | Append STDOUT to file |
| 2>> | Append STDERR to file |
| 3>> | Append all output to file |
| 2>&1 | Redirect STDERR to STDOUT |
| <<WORD | Redirect multiple line from keyboard to STDIN with <<WORD |
Pipe
-
COMMAND1 | COMMAND2- send STDOUT of COMMAND1 to STDIN of COMMAND2 instead of the screen
- STDERR is not forwarded across pipes
![linux_pipe]()
-
COMMAND1 | tee [-a] FILE | COMMAND2stores STDOUT of COMMAND1 in FILE, then pipes to COMMAND2
常用组合
Examples:
-
echo > test![1]()
-
find /etc/ -name passwd &> find.all![2]()
-
find /etc/ -name passwd 2>&1 | head2>&1: Redirects STDERR to STDOUT
- Useful for sending all output through a pipe
![3]()
-
(cal 12 2018 ; cal 1 2019) | head -n 12![4]()
-
find /etc/ -name passwd &> /dev/null -
find /etc/ -name passwd > find.out 2> find.err![5]()
-
find /etc/ -name passwd 2> /dev/null | tee find.out | head![6]()
-
cat > test.sh << EOF![7]()









浙公网安备 33010602011771号