Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How could I enter a command, say, system_profiler, and have the output save somewhere on my computer?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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.

share|improve this answer
    
&>> doesn't seem to work in Mac Bash version 3.2.48(1)-release (x86_64-apple-darwin11). I when I try it, it says -bash: syntax error near unexpected token >. Everything else works. –  Nacht Apr 25 '13 at 18:19

Redirection.

awesomo > somefile.txt
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.