曲径通幽论坛

标题: 文件重定向 [打印本页]

作者: beyes    时间: 2008-12-29 23:56
标题: 文件重定向
command > filename               //把标准输出重定向到一个新文件中

command >> filename              //把标准输出重定向到另一个文件中(追加而非覆盖方式)

command 1 > filename             //把标准输出重定向到一个

command > filename 2>&1           //把标准输出和标准错误一起重定向到一个文件中

command 2 > filename             //把标准错误重定向到一个文件中

command 2 >> filename            //把标准错误以追加非覆盖的方式重定向到一个文件中

command >> filename 2>&1          //把标准输出和标准错误一起重定向到一个文件中(追加)

command < filename > filename2    //command命令以 filename 文件作为标准输入,以 filename2 文件作为标准输出

command < filename               //command 命令以 filename 文件作为标准输入

command << delimiter              //从标准输入中读入,直至遇到 delemiter 分界符

command < &m                   //把文件描述符 m 作为标准输入

command > &m                   //把标准输出重定向到文件描述符 m 中

command < &-                     //关闭标准输入
作者: beyes    时间: 2008-12-30 00:21
file 文件有以下内容:
hello
jam
tom
beyes
admin
root

运行命令:
cat file | sort 1> file2
注意: 1 和 > 符号中间不能有空格

file2 中内容为:
hello
jam
tom
beyes
admin
root

作者: beyes    时间: 2008-12-30 00:25
标题: &gt; 也可以创建文件
如:
>nullfile

作者: beyes    时间: 2008-12-30 01:04
标题: 文件界定符的应用
设有文件: term.txt
其中内容: test line

现在执行以下命令:
cat >>term.txt<<delimiter
出现提示符 >

接着输入:
> hello,i am using a $TERM terminal
> and my username is $LOGNAME
> bye ...
> delimiter

输入到 delimiter 结束,看一下 term.txt 的内容:
[root@localhost Desktop]# cat term.txt
test line
hello,i am using a xterm terminal
and my username is beyes
bye ...

可见,输入的内容是被追加到 term.txt 中。在输入时遇到 delimiter 时结束。

cat 不接参数时,只要输入什么就会立即回显什么,直到遇到 ctrl+c 或 ctrl+d 为止。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2