Ted's Blog

Happy coding

重定向操作符

Ted posted @ 2008年8月21日 21:01 in 未分类 with tags redirect , 4090 阅读

经常看到这样的语句:mysh > mylog.txt 2>&1是什么意思?

 

重定向操作符可以用来将命令输入和输出数据流从默认位置重定向到其他位置,其输入或输出数据流的位置称为句柄;常见的句柄有三种,当然句柄可以自行扩展,一般的OS都提供类似的功能:

 

句柄 句柄代号 句柄描述
STDIN 0 键盘输入
STDOUT 1 输出信息到提示符窗口
STDERR 2 输出错误信息到提示符窗口

默认的 < 重定向输入操作符是 0,而默认的 > 重定向输出操作符是 1。键入 < 或 > 操作符之后,必须指定数据的读写位置,可以是文件名或其他现有的句柄。
要指定重定向到现有句柄,请使用与 & 字符,后面接要重定向的句柄号(即 &句柄号)。
例如,下面的命令可以将句柄 2(即 STDERR)重定向到句柄 1(即 STDOUT):2>&1
下表列出了可用于重定向输入和输出数据流的操作符:

 

重定向操作符 功能描述
> 将命令输出写入文件或设备,而不是命令提示符或句柄
< 从文件而不是从键盘或句柄读入命令输入
>> 将命令输出添加到文件末尾而不删除文件中已有的信息
>& 将一个句柄的输出写入到另一个句柄的输入中
<& 从一个句柄读取输入并将其写入到另一个句柄输出中
| 从一个命令中读取输出并将其写入另一个命令的输入中;也称为管道操作符

现在我们回过头来看看上面的那条语句mysh > mylog.txt 2>&1就可明白:

> mylog.txt意思是将标准输出重定向到mylog.txt,等价于mysh 1> mylog.txt;

2 >& 1 意思是将错误输出重定向到句柄1标准输出;综合起来就是mysh命令执行过程中产生的标准输出和错误输出都会被重定向到mylog.txt中;

重定向的功能十分强大,有兴趣的可以去尝试各种不同的组合,看看前后位置变下会有什么结果?

某些时候我们可能并不希望记录什么标准输出或者是错误输出,那可以用mysh >null 2>null或者mysh >/dev/null 2>/dev/null;

Avatar_small
LEGEND SEO 说:
2020年12月19日 15:16

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. kissmanga

Avatar_small
SEO 说:
2021年2月01日 20:03 We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. Soccer Backpacks
Avatar_small
SEO 说:
2021年2月09日 17:37

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. D health ประกันสุขภาพเหมาจ่าย

Avatar_small
SEO 说:
2021年2月09日 17:41

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. รับทำ seo

Avatar_small
전설 서구 说:
2021年2月14日 15:47

I think that thanks for the valuabe information and insights you have so provided here. schlüsseldienst in Hannover

Avatar_small
SEO 说:
2021年2月27日 18:05

This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. bafang bbshd 1000w

Avatar_small
SEO 说:
2021年3月01日 19:53

This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. CRA-Z-ART SHIMMER N'SPARKLES BATH BOMBS-MAKE YOUR OWN SCENTED BATH BOMBS

Avatar_small
SEO 说:
2021年3月03日 17:03

This is my first visit to your web journal! We are a group of volunteers and new activities in the same specialty. Website gave us helpful data to work. tutoring centers near me

Avatar_small
mooi residences show 说:
2021年3月17日 19:17

Seite Positive, WO HAST du Die Informationen zu diesem Beitrag gefunden? Ich bin FrOH, dass es entdeckt the ICH habe. Ich Werde Bald wiederkommen, UM herauszufinden, Welche zusätzlichen Beiträge Sie hinzufügen. Https://myspace.com/casinoanmeldung

Avatar_small
SEO 说:
2021年3月27日 21:10

HDMp3converter.com is a smart online Youtube Mp3 converter and downloader that allows users to convert favorite YouTube videos into Mp3, Aac, & M4a format.HD YouTube to Mp3 converter and downloader is a smart online Mp3 converter that allows users to convert favorite YouTube videos into Mp3, Aac, & M4a format. Youtube To Mp3 Converter

Avatar_small
mooi residences show 说:
2021年4月05日 18:39

Sehr informativer Beitrag! Hier finden Sie viele Informationen, die jedem Unternehmen helfen können, mit einer erfolgreichen Social-Networking-Kampagne zu beginnen. https://de.eyeka.com/u/casinoohneanmeldung

Avatar_small
moiz 说:
2021年4月26日 20:21

Thank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as ABC. visit my profile

Avatar_small
moiz 说:
2021年4月28日 19:00

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. daftar joker123

Avatar_small
moiz 说:
2021年5月04日 19:21

Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. yoga massage

Avatar_small
SEO 说:
2021年5月06日 18:39

Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. MASTERY REVIEWS

Avatar_small
moiz 说:
2021年5月17日 19:56

I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,.. 파워볼사이트

Avatar_small
SEO 说:
2021年5月26日 20:39

I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... dark web links

Avatar_small
SEO 说:
2021年5月26日 20:41

I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... auto rolling shutter bd

Avatar_small
SEO 说:
2021年5月28日 11:54

I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... Bitcoin Market, Bitcoin Charts

Avatar_small
SEO 说:
2021年5月30日 03:49

I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... Dabwoods

Avatar_small
SEO 说:
2021年6月06日 20:25

Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. 토토사이트

Avatar_small
dark web/deep web/d 说:
2022年8月04日 18:52

There is nothing to stop someone from creating thousands of fake links and advertising them on the Internet.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:38

Some sites also contain embedded images and video, which users often do not want to open and view. In addition, many of these dark web links contain a "pay-per-click" advertising program that allows advertisers to display their ads right in front of millions of web users.  deep web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:52

By being cautious about where you post your information and making sure that sites that you visit do not contain harmful embedded scripts, you can reduce your risk of becoming a victim.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:14

There are many commonalities in these links as well. Some of them are link farms, automated websites, spam links, and phishing scams. There are a few other things as well.   dark web sites

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:30

You also need to be aware of the fact that when you are looking at these links, you are going to get a lot of information on the site. Some of it might be worth reading, and some could be harmful. So just be careful who you associate with and don't give out credit card numbers online! But you can enjoy the dark web if you learn how to work around the dangers.  dark web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:44

Affiliate marketing is all about finding the right product to market, and you have to focus on the right niche in order to make any money at all.   work from home jobs

Avatar_small
dark web/deep web/d 说:
2022年8月04日 21:02

The series went so well that it earned the company $4 million in sales in its first three months. The secret to their affiliate marketing success stories?  affiliate marketing success

Avatar_small
jsimitseo 说:
2024年1月30日 22:23

These things are vital, great think so - I suspect as much as well...  concierge doctor naples


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter