Save Terminal Output command on OSX
14,410
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 videos on Youtube
Author by
hzleonardo
Updated on September 18, 2022Comments
-
hzleonardo over 1 year
It is simple question but couldn't find the answer, I found and tried
tee output.txt
andsystem_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?-
BloodyEl almost 8 yearsYour command should work fine. Please see my tested answer.
-
hzleonardo almost 8 yearsYes you are right, I waited like 1-2 minutes and text file is not blank anymore but it doesn't save the output, it saves application's detail stuff. I am speaking of
system_profiler > output.txt
-
BloodyEl almost 8 years"system_profiler > output.txt" has the exact same effect as "system_profiler", except saved to a file. "system_profiler -xml > output.txt" will print in an xml format that is sometimes useful but not what you are looking for. Can you show me the difference you get between "system_profiler" and the file from: "system_profiler > output.txt"? I'm using exactly the same syntax as you. I get exactly the same thing, the expected result.
-
BloodyEl almost 8 yearsThere is something missing. Either you are cancelling the command mid-way, or you are not satisfied with the original output of "system_profiler" as it is without printing. Whether printing to file or not, the result is massive. If you only want to limit the results to the first paragraph, then use "system_profiler --timout 5 > output.txt" and it will stop itself. That is not a printing issue. Please explain how the result in the file is different from the result on screen. CONFIRM YOU ARE NOT SENDING SIGKILL [CTRL-C] etc.... because then we are not doing the same thing at all.
-
hzleonardo almost 8 yearsYes I do CTRL-C. When I do it there is no problem when I save terminal output manually, why would it be a problem to do it with command?
-
-
dave_thompson_085 almost 8 yearsI don't have Mac but every shell I've ever seen does explicit (i.e. other than pipe) redirections in the order given, so you need
>output 2>&1
. Alternatively in bash you can use&>output
or>&output
to do both at once; see the man page. -
ljrk almost 8 yearsI only use OSX in a Virtual Machine, my primary is Linux -- and every shell I've used works with both ways.
-
dave_thompson_085 almost 8 yearsNot the two Linuxes I currently use: on Ubuntu(14) with
bash
ordash
, doingcat bad 2>&1 >output
sends the error message to the tty and nothing to the file; on CentOS(6) withbash
ordash
orksh93
the same, and withtcsh
it gives an errorAmbiguous output redirection
. Could you give me an example I can download (on x86-64) or connect to that works for that form? -
hzleonardo almost 8 yearsAm I the only one who is doing something wrong? I see these commands everywhere but it doesn't work for me, I waited, still blank text file. Are you el capitan 10.11.5?
-
hzleonardo almost 8 yearsStill blank text file and no success, it may be an el capitan issue? Are you on latest el capitan?
-
ljrk almost 8 years@dave_thompson_085 I just noticed I only use
command 2>&1 | tee output.txt
which does work this way around, but you're right, for>
it doesn't. I never noticed O.o -
ljrk almost 8 years@hzleonardo I just fired up ElCapitan 10.11.5 and yes it works, you just need to give it some time. You do not even need the stderr-redirection except you want to get info about devices that didn't respond etc. For me it took quite some time:
time system_profiler > out.txt 2> err.txt 23.36s user 39.51s system 96% cpu 1:04.97 total
, so perhaps just wait ... -
hzleonardo almost 8 yearsYes same result for me too which I don't want. I am trying to do "Export Text As" in shell menu with a command. When I do it manually it's ok, only print's from terminal in the text file in a second but with commands, blank file or this output in text after 1-2 minutes.