惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
U
Unit 42
W
WeLiveSecurity
博客园 - Franky
Recent Announcements
Recent Announcements
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
月光博客
月光博客
The Cloudflare Blog
Spread Privacy
Spread Privacy
腾讯CDC
P
Privacy International News Feed
N
News and Events Feed by Topic
AWS News Blog
AWS News Blog
NISL@THU
NISL@THU
T
Troy Hunt's Blog
小众软件
小众软件
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Microsoft Security Blog
Microsoft Security Blog
L
Lohrmann on Cybersecurity
Webroot Blog
Webroot Blog
Y
Y Combinator Blog
量子位
P
Palo Alto Networks Blog
N
News and Events Feed by Topic
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
IT之家
IT之家
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
云风的 BLOG
云风的 BLOG
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
G
Google Developers Blog
S
Secure Thoughts

博客园 - taizi

Redhat5 网络配置(转) RPM 用法 Beginning Linux Programming----The Standard I/O Library Beginning Linux Programming----Low-level File Access (3) Beginning Linux Programming----Low-level File Access (2) Beginning Linux Programming----Low-level File Access (1) Beginning Linux Programming----Library Functions Beginning Linux Programming----System Calls and Device Drivers /dev/null 和/dev/zero(摘) Beginning Linux Programming----Linux File Structure Beginning Linux Programming----shell脚本程序实例 Beginning Linux Programming----dialog Utility Beginning Linux Programming----Debugging Scripts Beginning Linux Programming----Here Documents Beginning Linux Programming----Command Execution,Arithmetic Expansion,Parameter Expansion Beginning Linux Programming----Grep Beginning Linux Programming----Find Bash提示小窍门 Beginning Linux Programming----Commands(2)
细细品味UNIX的数据流重定向(摘)
taizi · 2008-04-01 · via 博客园 - taizi

  我们经常会在UNIX系统下的一些脚本中看到类似”2>&1″这样的用法,例如“/path/to/prog 2>&1 > /dev/null &”,那么它的具体含义是什么呢?

   UNIX有几种输入输出流,它们分别与几个数字有如下的对应关系:0-标准输入流(stdin),1-标准输出流(stdout),2-标准错误流 (stderr)。”2>&1″的意思就是将stderr重定向至stdout,并一起在屏幕上显示出来。如果不加数字,那么默认的重定向 动作是针对stdout(1)的,比如”ls -l > result”就等价于”ls -l 1 > result”。这样便于我们更普遍性的理解重定向过程。

下面举例说明:

#cat std.sh
#!/bin/sh
echo “stdout”
echo “stderr” >&2

#/bin/sh std.sh 2>&1 > /dev/null
stderr

#/bin/sh std.sh > /dev/null 2>&1

   第一条命令的输出结果是stderr,因为stdout和stderr合并后一同重定向到/dev/null,但stderr并未被清除,因此仍将在屏 幕中显示出来;第二条命令无输出,因为当stdout重定向至/dev/null后,stderr又重定向到了stdout,这样stderr也被输出到 了/dev/null。