Write strace output to a file
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 of strace 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
Related: piping strace to grep however it will likely be simpler to use the strace -o option rather than shell redirection
2 Answers 2
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.
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 of strace but I didn’t see the -o option, my fault. Thanks!
no 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.
What on Earth makes you think that you cannot redirect standard error or arrange for it to be sent through a pipe to grep ?