Linux基础之标准输入和输出

来源:互联网 发布:八音盒音乐制作软件 编辑:程序博客网 时间:2024/06/05 08:35

前言

 

tail -lf   W1E2B2_* 

-f
            If the input file is a regular file or if the File parameter specifies a FIFO (first-in-first-out), the tail command does not terminate after
            the last specified unit of the input file has been copied, but continues to read and copy additional units from the input file as they become
            available. If no File parameter is specified and standard input is a pipe, the -f flag is ignored. The tail -f command can be used to monitor
            the growth of a file being written by another process.

正文

1.Linux提供了三种输入/输出通道给程序


标准输入(STDIN) - 缺省为键盘
 标准输出(STDOUT) - 默认为终端窗口

 标准错误(STDERR) - 默认为终端窗口

2.标准输出和标准错误能重定向到文件中:
命令   操作 文件名
 支持的操作包括:
 > 重定向标准输出到文件
 2> 重定向标准错误到文件
 &> 重定向所有的输出到文件
· 文件内容模式被覆盖. >> 用在追加.

3重定向输出给一个文件示例
· 作为非root用户这个命令生成输出和错误:
$ find /etc -name passwd
· 通常保存操作的输出和错误:
$ find /etc -name passwd > find.out
$ find /etc -name passwd 2> /dev/null
$ find /etc -name passwd > find.out 2> find.err

4.重定向标准输出给一个程序
· 管道(| 字符) 可以连接命令:
· command1 | command2
 发送command1 标准输出给command2 的标准输入而不
是终端屏幕.
 标准错误不会通过管道传递
· 通常用于组合多个命令处理功能
command1 | command2 | command3...

5.重定向标准标准输出给一个程序示例
· less: 一次显示输入的一页:
$ ls -l /etc | less
 输入可以通过/ 做查询
· mail: 通过邮件发送输入:
 echo "test email" | mail -s "test" user@example.com
· lpr : 发送输入到一台打印机
echo "test print" | lpr
echo "test print" | lpr -P printer_name


6.组合输出和错误
· 一些操作同时影响标准输出和标准错误
 &>: 重定向所有输出:
$ find /etc -name passwd &> find.all
2>&1: 重定向标准错误到标准输出
通过管道发送所有的输出非常有用

 find /etc -name passwd 2>&1 | less
(): 组合多个程序的标准输出
( cal 2007 ; cal 2008 ) | less

0 0
原创粉丝点击