Ubuntu中输入输出重定向及管道技术简述

输出

1、标准输出

  定义:程序在默认情况下输出结果的地方(stdout)。

2、输出重定向

  定义:用于把数据的输出转移到另一个地方去。

3、Ubuntu中例子

  $ls > ~/ls_out  ##不显示在显示器上而是输入到文件ls_out中

  uname -r > ls_out  ## output the kernal information to the file of ls_out

  date > ls_out ##output date to file ls_out

  uname >> ls_out  ##add to the tail of ls_out

输入

1、标准输入

  定义:默认情况下接受输入的地方。通常指的是键盘。

2、输入重定向  定义:非标准输入。例如从文件中导入(输入)等。

3、例子Ubuntu

  $cat < days  ##print the content in the days to the screen

  cat < EOF  ##立即文档,输入到EOF时停止。

  cat << END > hello ##合并使用

管道 |

  定义:将“重定向”又向前推了一步。通过一个“|”,将一个命令的输出连接到另一个命令的输入。

  例子: ls | grep ruby

  解析:ls首先列出所有文件的文件名,管道“|”接收到这些输出并把他们发送给grep命令作为其输入。最后grep在其中查找包含字符串ruby的文件名,并在标准输出(显示器)上面显示。

 

posted @ 2016-02-26 15:58  YouxiBug  阅读(1241)  评论(0编辑  收藏  举报