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. Java-异常初步练习

    案例一: package com.esandinfo; /** * 自定义一个Exception类 */ class MyCustomException extends RuntimeExceptio ...

  2. HTB Linux queuing discipline manual - user guide笔记

    1. Introduction HTB is meant as a more understandable, intuitive and faster replacement for the CBQ ...

  3. 关于Nginx设置端口号,在Asp.net 获取不到的,解决办法

    不知道你有没有遇到过这样的问题,网站访客多起来后,心里很是高兴,加上了Nginx反向代理,出问题了 原来是这么写的: Request.Url.ToString() 输出是这样的: http://www ...

  4. C实现动态进度条

    #include <iostream> #include <windows.h> void HideCursor() { CONSOLE_CURSOR_INFO cursor_ ...

  5. Java集合排序(面试必考点之一)

    集合是Java面试必考知识点,而集合的排序也是非常重要的,工作中经常用到,那么这个知识点也是必须要掌握的,下面是我曾经面试时被面试官问的问题: 根据API可知,Java集合的工具类Collection ...

  6. 10分钟看懂Docker和K8S

    本文来源:鲜枣课堂 2010年,几个搞IT的年轻人,在美国旧金山成立了一家名叫"dotCloud"的公司. 这家公司主要提供基于PaaS的云计算技术服务.具体来说,是和LXC有关的 ...

  7. 实现简易Promise

    概述 异步编程离不开promise, async, 事件响应这些东西,为了更好地异步编程,我打算探究一下promise的实现原理,方法是自己实现一个简易的promise. 根据promise mdn上 ...

  8. Robot Framework - 2 - 创建测试库

    04- 创建测试库--基础概念 Robot Framework 实际的测试能力是由测试库提供的. ***** 支持的编程语言 Robot Framework 自身是用 Python 编写的,能使用 P ...

  9. iOS学习——更改导航栏的返回按钮的标题与颜色

    转载自:修改navigationController返回按钮颜色和文字 今天在做项目时遇到这个问题,试了很多方法都失败了.最后终于找到正确的方案了,在这里分享给大家. 引言 在iOS开发过程中,Nav ...

  10. tensorflow 迭代周期长,每个epoch时间变慢

    理论上,session启动后,每个epoch训练时间应该是差不多,而且不会因为迭代周期变长,epoch时间变慢.原因是session里定义了tf.op导致的,每一次迭代都会在graph里增加新的节点, ...