@ghostfn1
2016-03-01T17:47:47.000000Z
字数 846
阅读 1992
Shell
Linux
Update Time:160301 Teusday
大多数 UNIX 系统命令从你的终端接受输入并将所产生的输出发送回到您的终端。一个命令通常从一个叫标准输入的地方读取输入,默认情况下,这恰好是你的终端。同样,一个命令通常将其输出写入到标准输出,默认情况下,这也是你的终端。
1、输出重定向
[centos@localhost ~]$ ls > abc
[centos@localhost ~]$ cat abc
abc
game2.sh
game.sh
hello.sh
[centos@localhost ~]$ ls >>abc
# Add content but not erase.
cat abc
lst 2 >abc
# Output the wrong message
2、输入重定向
command1 < file1
command1 << file1
3、
When run a Unix/Linux command, three files will be open:
stdin, stdout and stderr. The file descriptors for them are 0, 1 and 2. As a result, we could use commands like these:
command >file 2>&1
command >>file 2>&1
command &> file
command &>> file
# To save both the wrong and right messages.
4、
The command won't be shown on the winwod using the dev/null file.
$ command > /dev/null
$ command > /dev/null 2>&1
# stdout and stderr
command >>abc 2>>def
//save to abc and def.
Examples:
wc < abc
# Ctrl+d to exit.
wc <<hello
>asdca
>asa
>hello
# When you input hello again,it will exit.