Macos – Save Terminal Output command on OSX

command linemacmacososx-el-capitanterminal

It is simple question but couldn't find the answer, I found and tried tee output.txt and system_profiler > output.txt but no success, they save blank text file. How do I save my terminal output with command in terminal on OSX El Capitan?

Best Answer

Assuming command is the command you want to run, you can pipe it's output into the output.txt using:

$ command > output.txt

or

$ command | tee output.txt

If this doesn't hell it may be because the output is not printed on stdout but on stderr. The pipe > is implicit writing for 1> which means "pipe stdout to ...".
If you want to pipe stderr into the file too, you can use

$ command >output.txt 2>&1

This pipes all the output of stderr to the file-descriptor 1 (=stdout) which in turn is piped into the text file.

Related Question