Save Terminal Output command on OSX
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?
3 Answers
Assuming command is the command you want to run, you can pipe it's output into the output.txt using:
$ command > output.txtor
$ command | tee output.txtIf 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>&1This pipes all the output of stderr to the file-descriptor 1 (=stdout) which in turn is piped into the text file.
Syntex:
$command > /output/file/locationExample: suppose you want to list out all files and directories of /home/jackson and save its result to /home/jackson/list.txt so command will be--
$ls /home/jackson > /home/jackson/list.txtbut remember if file /home/jackson/list.txt is already exist and contain information, then previous command will erase your previous information and write your command output. so that if you dont want to erase your previous information use ">>" instead of ">". so your command will be.
$ls /home/jackson >> /home/jackson/list.txtHope that will help..
1Q. How do I save my terminal output with command in terminal on OSX El Capitan?
A. Simply give your computer enough time to complete that particular command (1m30s or so).
Your command should run without issue.
On my mac the command:
system_profiler > output.txt.. Takes about 1m30s to complete.
System profiler also has formatting options and a time-limit if desired.
system_profiler -xml -timeout 3 > textfile.xml
cat ./textfile.xmlReference:
man system_profiler
system_profiler -usageResult (with nl to count the line numbers). This file is the same as the command and is about 52000 lines.
system_profiler > output.txt nl output.txt
1 Accessibility: 2 Accessibility Information: 3 Cursor Magnification: Off 4 Display: Black on White 5 Flash Screen: Off 6 Mouse Keys: Off 7 Slow Keys: Off 8 Sticky Keys: Off 9 VoiceOver: Off 10 Zoom Mode: Full Screen
...
... 51937 Wake On Wireless: Supported 51938 AirDrop: Supported, Channel 0 51939 Status: Off 1