here are three types of I/O, which each have their own identifier, called a file descriptor:

  • standard input: 0

  • standard output: 1

  • standard error: 2

In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is <, the redirection refers to the standard input (file descriptor 0). If the first character
of the redirection operator is >, the redirection refers to the standard output (file descriptor 1).

Some practical examples will make this more clear:

ls > dirlist 2>&1

will direct both standard output and standard error to the file dirlist, while the command

ls 2>&1 > dirlist

will only direct standard output to dirlist. This can be a useful option for programmers.

Things are getting quite complicated here, don't confuse the use of the ampersand here with the use of it inSection
4.1.2.1
, where the ampersand is used to run a process in the background. Here, it merely serves as an indication that the number that follows is not a file name, but rather a location that the data stream is pointed to. Also note that the bigger-than sign
should not be separated by spaces from the number of the file descriptor. If it would be separated, we would be pointing the output to a file again. The example below demonstrates this:

[nancy@asus /var/tmp]$ ls 2> tmp

[nancy@asus /var/tmp]$ ls -l tmp
-rw-rw-r-- 1 nancy nancy 0 Sept 7 12:58 tmp [nancy@asus /var/tmp]$ ls 2 > tmp
ls: 2: No such file or directory

The first command that nancy executes is correct (eventhough no errors are generated and thus the file to which standard error is redirected is empty). The second command expects that 2 is
a file name, which does not exist in this case, so an error is displayed.

All these features are explained in detail in the Bash Info pages.

Advanced redirection features的更多相关文章

  1. Enhancing the Application: Advanced JDBC Features(转)

    Enhancing the Application: Advanced JDBC Features This chapter describes additional functionality th ...

  2. Spring Security(二十一):6.3 Advanced Web Features

    6.3.1 Remember-Me Authentication (记住我的身份验证) See the separate Remember-Me chapter for information on ...

  3. # advanced packaging

    目录 advanced packaging ASM NEXX ASMPT完成收購NEXX 準備就緒迎接先進半導體封裝之高速增長 Intro Bumping 产品供应 晶圆溅镀– Apollo 300 ...

  4. 2.Kali安装VMware tools(详细+异常处理)

    dnt@MT:~$ cd /media/cdrom0 进入光驱内 dnt@MT:/media/cdrom0$ ls 查看当前目录下有哪些内容manifest.txt run_upgrader.sh V ...

  5. 【转】虚拟机VMware与主机共享文件介绍

    from: http://www.cnblogs.com/kerrycode/p/3818095.html 写的比较详细,但是vm版本较旧. 2:通过共享文件夹功能 虚拟机VMware提供了在宿主机与 ...

  6. Deployment options

    Play applications can be deployed virtually anywhere: inside Servlet containers, as standalone serve ...

  7. 分享15个优秀的 CSS 解决方案和工具

    CSS 代码是很难管理,尤其是在大型项目. 样式都写在一个全局作用域里,通过复杂的选择器来指向特定的页面元素.冗余.膨胀和维护可以成为前端开发人员的一场噩梦.幸运的是我们有一些 CSS 工具来帮助开发 ...

  8. Oracle Linux 5.7安装VMware Tools的问题

    案例环境介绍:     虚拟机的版本:VMware® Workstation 8.0.3 build-703057    操作系统版本:Oracle Linux Server release 5.7 ...

  9. 虚拟机VMware与主机共享文件介绍

    我们经常会在Windows平台安装虚拟机VMware,不管是出于实验测试还是工作需要,伴随而来的就是经常需要在Windows系统和虚拟机系统之间进行共享数据文件,例如,需要将Window主机上的Ora ...

随机推荐

  1. 架构(一)JDK安装

    一 遇到的问题 问题1:安装jdk的时候,jdk解压失败? 我是通过wget http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b84 ...

  2. 【高速接口-RapidIO】2、RapidIO串行物理层的包与控制符号

    一.RapidIO串行物理层背景介绍 上篇博文提到RapidIO的物理层支持串行物理层与并行物理层两种,由于Xilinx 部分FPGA内部已经集成了串行高速收发器,所以用FPGA实现RapidIO大多 ...

  3. Android 图片高级绘图效果---高斯模糊

    高斯模糊就是将指定像素变换为其与周边像素加权平均后的值,权重就是高斯分布函数计算出来的值.高斯模糊能够将图片制作成类似磨砂的图片效果,一般这些图片都用来作为背景. 目前使用到的是RenderScrip ...

  4. InnoDB Insert Buffer(插入缓冲)

    InnoDB Insert Buffer(插入缓冲) 每个存储存储引擎自身都有自己的特性(决定性能以及更高可靠性),而InnoDB的关键特性有: 插入缓冲(Insert Buffer)-->Ch ...

  5. vue局部组件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 第34节:Java当中的异常

    Java当中的异常 了解Java当中的异常,那么什么是异常呢?异常又有什么分类呢?异常中的特殊结构:try...catch...finally 结构的使用方法. 异常是一种对象,是靠虚拟机产生的,异常 ...

  7. Scala - 快速学习07 - 模式匹配

    Scala中的模式匹配的功能可以应用到switch语句.类型检查.“解构”等多种场合. 简单匹配 Scala的模式匹配最常用于match语句中.Scala的match语句类似Java里的switch. ...

  8. java mongodb的MongoOptions生产级配置

    autoConnectRetry仅仅意味着驱动程序会自动尝试重新连接到意外断开连接后在服务器(一个或多个).在生产环境中,您通常需要将此设置为true. connectionsPerHost是物理连接 ...

  9. odoo开发笔记 -- 模型字段定义中设置默认值

    例如: company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env['res ...

  10. 短视频 SDK 6大功能技术实现方式详解

    第三方短视频解决方案作为快速切入短视频行业的首选方式,选择一款功能齐全.性能优异的短视频解决方案十分重要. 今天我们来谈谈短视频 SDK 6大重要功能点及其技术实现方式. 短视频拍摄 断点续拍 指在拍 ...