Write strace output to a file
15,399
By default strace outputs to stderr. By simply typing man strace
, you will have the full documentation of strace
. In the manual page, it states that the -o
option can be used to output it to a file instead of stderr. You can type man [insert command here]
for the vast majority of programs, and have all the documentation you will need to effectively use them.
Author by
yeled zevel
Updated on September 18, 2022Comments
-
yeled zevel almost 2 years
I'm trying to write the output of
strace ls
to a file. I know that I need to use>
in order to forward output of a command to a file, but it doesn't work. It creates a file but the command prints the output ofstrace ls
to stdout but writes the file name into the file.$ strace ls > ls_sys.txt ... strace output ... $ cat ls_sys.txt ls_sys.txt
-
smw almost 4 yearsRelated: piping strace to grep however it will likely be simpler to use the strace
-o
option rather than shell redirection -
fpmurphy almost 4 yearsHave you tried
strace -o ls_sys.txt ls
?
-
-
yeled zevel almost 4 years
By default strace outputs to stderr, which is not accessible via grep or file redirection
. Good to know! And I looked at the manual page ofstrace
but I didn't see the-o
option, my fault. Thanks! -
john doe almost 4 yearsno problem, I actually just figured out this strace option myself yesterday. When you are in a man page, you can press
/
and it will bring a dialog that you can search. In my case, I simply searched for output and found the part of the man page I was looking for. -
JdeBP almost 4 yearsWhat on Earth makes you think that you cannot redirect standard error or arrange for it to be sent through a pipe to
grep
? -
Stephen Kitt almost 4 yearsstderr can be redirected, using
2>
. See this question. -
Stéphane Chazelas over 2 yearsNote that it redirects both the
strace
tracing and the./elf_file
errors tostrace_output.txt
. For that reason, it's better to usestrace -o strace_output.txt ./elf_file
orstrace -o strace_output.txt ./elf_file 1> stdout.txt 2> stderr.txt
if you want traces, stdout and stderr in different files. -
alkino over 2 yearsA bash-ism I guess is
command |& command
it merges and pipes both stdout and stderr to the next command.