在做批量实验室,例如跑批量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/

44 对 “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.

发表评论

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