在做批量实验室,例如跑批量MR的作业,我们会写好shell脚本,然后启动脚本,等所有作业执行完再去看结果,但是这些执行时的信息如何保存下来到文件中呢?下面这个命令可以完成这个任务。


其中sh batchjob.sh:表示要执行的shell脚步;0,1,2:在linux分别表示标准输入、标准输出和标准错误信息输出。

下面来总结下重定向问题。

 

输入输出重定向之:'<‘ and ‘>’

‘<‘ and ‘>’分别用来支持linux中的输入输出重定向,其中'<‘支持输入重定向,’>’支持输出重定向。

1. ‘<‘:重定向输入

sh test.sh < hadoop-hadoop-jobtracker-brix-00.out,将hadoop-hadoop-jobtracker-brix-00.out的内容作为test.sh的输入

2. ‘>’:将内容全局覆盖式的加入文件,相当于删除该文件并重新建立该文件,再写入的效果

ls * > test.txt ,将ls * 的所有信息输出到文件test.txt中

3. ‘>!’:如果存在则覆盖

4. ‘>&’:执行时屏幕上所产生的任何信息写入指定的文件中

5. ‘>>’:追加到文件中

6. ‘>>&’:屏幕上的信息追加到文件中

标准输入输出

在 Linux 系统中:标准输入(stdin)默认为键盘输入;标准输出(stdout)默认为屏幕输出;标准错误输出(stderr)默认也是输出到屏幕(上面的 std 表示 standard)。在 BASH 中使用这些概念时一般将标准输出表示为 1,将标准错误输出表示为 2。下面我们举例来说明如何使用他们,特别是标准输出和标准错误输出。

tee命令

tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。

复制代码

复制代码

 

转载:http://www.cnblogs.com/gslyyq/

88 对 “linux重定向总结:如何将shell命令的输出信息自动输出到文件中保存”的想法;

  1. Gгeat website уou haᴠe һere but І was curioous if
    yօu knew of ɑny forums that cover the samе topics talked
    aƅout in this article? I’d really like
    to be a рart of ɡroup wһere I ϲan get comments from otheг experienced individuals that share the same interest.

    If you һave anny recommendations, pⅼease let me know.
    Thank ʏoᥙ!

  2. I think everything said made a ton of sense. But, think on this,
    suppose you were to create a awesome title? I ain’t suggesting your information is not good., however suppose
    you added something that makes people desire more?
    I mean linux重定向总结:如何将shell命令的输出信息自动输出到文件中保存 –
    加加笔记 is a little boring. You ought to peek at Yahoo’s home page and see how they write
    news titles to grab people interested. You might try adding a video or a pic or two to get
    people excited about what you’ve written. In my opinion, it could make your blog a little livelier.

  3. Hi there, I do think your site could be having web browser compatibility issues.

    Whenever I take a look at your blog in Safari, it
    looks fine but when opening in Internet Explorer, it’s got some overlapping issues.
    I just wanted to give you a quick heads up! Other than that, excellent site!

  4. Hi there, I found your web site by way of Google
    even as looking for a related subject, your site got
    here up, it seems great. I have bookmarked it in my google
    bookmarks.
    Hi there, simply become aware of your blog through Google, and found that it’s truly informative.
    I’m going to be careful for brussels. I will appreciate
    for those who proceed this in future. Many people will be
    benefited from your writing. Cheers!

  5. I’m no longer certain the place you are getting your information, but good topic.
    I needs to spend some time studying more or working out more.

    Thanks for wonderful information I was in search
    of this information for my mission.

  6. Yesterday, while I was at work, my sister stole my iPad and tested to
    see if it can survive a 40 foot drop, just so she can be a
    youtube sensation. My apple ipad is now broken and she has 83 views.
    I know this is completely off topic but I had to share it with someone!

  7. I am curious to find out what blog platform you have been utilizing?

    I’m having some small security problems with my latest website and I would
    like to find something more risk-free. Do you have any suggestions?

  8. Excellent pieces. Keep posting such kind of information on your page.
    Im really impressed by your site.
    Hey there, You have performed an excellent job. I will certainly digg it and
    for my part recommend to my friends. I am confident they’ll be benefited from this web
    site.

  9. Hey there, I think your blog might be having browser compatibility issues.
    When I look at your website in Opera, it looks fine but when opening in Internet
    Explorer, it has some overlapping. I just wanted to give you a quick heads up!
    Other then that, wonderful blog!

  10. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire
    someone to do it for you? Plz answer back as I’m looking
    to create my own blog and would like to know where
    u got this from. thanks

  11. I simply could not depart your site before suggesting that I really loved the standard information an individual provide in your visitors?
    Is going to be back ceaselessly to check out new posts

  12. Its like you read my mind! You appear to know a lot about this, like you
    wrote the book in it or something. I think that you can do with some
    pics to drive the message home a bit, but instead
    of that, this is excellent blog. A great read.
    I’ll definitely be back.

  13. If some one desires expert view on the topic of blogging and
    site-building afterward i advise him/her to pay a quick visit
    this blog, Keep up the nice work.

  14. Excellent article. Keep writing such kind of info on your site.
    Im really impressed by your blog.
    Hi there, You have done a fantastic job. I’ll definitely digg it and for my part recommend to my friends.

    I am confident they’ll be benefited from this web site.

  15. Hey! Quick question that’s totally off topic. Do you know how to make your site mobile friendly?
    My site looks weird when browsing from my iphone 4. I’m trying to find a template
    or plugin that might be able to correct this issue.

    If you have any recommendations, please share.

    Appreciate it!

  16. Unquestionably believe that which you said. Your favorite reason appeared to be on the web the easiest thing to be aware of.
    I say to you, I definitely get irked while people think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top as well as defined out the
    whole thing without having side-effects ,
    people can take a signal. Will probably be back to get more.
    Thanks

  17. Greate article. Keep writing such kind of information on your
    blog. Im really impressed by your site.
    Hello there, You’ve done a great job. I will certainly digg it and
    personally suggest to my friends. I’m confident they’ll be benefited from this website.

  18. Great blog you have here but I was curious if you knew of any message boards that cover
    the same topics talked about in this article? I’d really love to be a part of
    online community where I can get responses from other experienced people that share the same interest.
    If you have any recommendations, please let me
    know. Many thanks!

  19. I am really impressed together with your writing skills and also
    with the layout in your blog. Is this a paid topic or did
    you customize it your self? Either way keep up the nice quality writing,
    it is uncommon to look a great weblog like this one
    these days..

  20. Good day! I could have sworn I’ve been to this web site before but after going through many of the posts I realized it’s new to me.
    Regardless, I’m definitely pleased I stumbled upon it
    and I’ll be book-marking it and checking back frequently!

  21. Oh my goodness! Awesome article dude! Thank you, However I am
    having troubles with your RSS. I don’t understand
    the reason why I am unable to join it. Is there anybody else having similar
    RSS problems? Anybody who knows the solution can you kindly respond?
    Thanx!!

  22. Greetings from Colorado! I’m bored to death at work so I
    decided to browse your website on my iphone during lunch break.
    I love the knowledge you provide here and can’t wait to take a look when I get home.
    I’m amazed at how quick your blog loaded on my phone ..
    I’m not even using WIFI, just 3G .. Anyhow, amazing site!

  23. Hello outstanding blog! Does running a blog like this take a lot
    of work? I have very little knowledge of coding but I had been hoping to start
    my own blog in the near future. Anyways, if you have any suggestions
    or techniques for new blog owners please share. I understand this is off subject however I just needed to ask.

    Thanks a lot!

  24. Can I just say what a comfort to uncover somebody who truly understands what they’re talking about online.
    You actually know how to bring a problem to light and make it important.

    A lot more people should look at this and understand this side of the story.

    I was surprised you are not more popular given that you certainly possess the gift.

  25. Hmm is anyone else experiencing problems with the images on this blog loading?

    I’m trying to find out if its a problem on my end or if it’s the blog.
    Any feed-back would be greatly appreciated.

  26. I really like your blog.. very nice colors & theme.
    Did you design this website yourself or did you hire someone to do it for you?
    Plz answer back as I’m looking to design my own blog and would like
    to find out where u got this from. appreciate it

  27. I believe that is among the such a lot significant info for me.
    And i’m glad studying your article. However wanna remark on few basic
    issues, The site style is ideal, the articles is in reality great : D.
    Excellent task, cheers

  28. My developer is trying to convince me to move to .net
    from PHP. I have always disliked the idea because of
    the expenses. But he’s tryiong none the less. I’ve been using
    WordPress on various websites for about a year and am concerned about switching to another platform.

    I have heard excellent things about blogengine.net.
    Is there a way I can import all my wordpress posts into it?
    Any help would be greatly appreciated!

  29. I’m extremely pleased to find this site. I want to to thank you for ones time due to
    this fantastic read!! I definitely really liked every bit of it and i also have you bookmarked to look at new stuff on your blog.

inhouse进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注