码迷,mamicode.com
首页 > 其他好文 > 详细

Save output to a text file from Mac terminal

时间:2014-08-20 11:57:42      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:http   os   io   for   ar   cti   div   html   

 

Simply with output redirection:

system_profiler > file.txt

Basically, this will take the output of system_profiler and save it to the file file.txt. There are technically two different output "streams", standard output, and standard error. They are treated separately, and if you use the simple redirection method above, you will only redirect standard output to the file. If you want to redirect both standard output and standard error, you could do this:

system_profiler &> file.txt

The & tells the shell to redirect the standard output and standard error to the file.

If you want to just output standard error, you can do this:

system_profiler 2> file.txt

The 2 lets the shell know that it needs to only redirect standard error.

Using the > will overwrite the file if it‘s already there. If you want to append it to a file without erasing the old one, you can use >>, like so:

system_profiler >> file.txt

You can of course use the & and 2 for sending both standard out and standard error, and just standard error with the >> operator.

Save output to a text file from Mac terminal,布布扣,bubuko.com

Save output to a text file from Mac terminal

标签:http   os   io   for   ar   cti   div   html   

原文地址:http://www.cnblogs.com/rosepotato/p/3923983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!