4 ms·
Another handy bit of syntax: $ command-name 2>&1 | less This combines standard out and standard error into one stream so you can read all the output in less
by salmonellaeater 13y ago
Another handy bit of syntax:
$ command-name 2>&1 | less
This combines standard out and standard error into one stream so you can read all the output in less [1]. Piping just standard out leads to stray error lines popping up on the screen while less is running, and they aren't kept in less's buffer so you lose track of them.
[1] http://www.cyberciti.biz/faq/redirecting-stderr-to-stdout/ http://www.cyberciti.biz/faq/redirecting-stderr-to-stdout/
- viraptor 13y agoShorter version in bash: |& less It redirects both outputs at once.
- kbenson 13y agoBe careful when redirecting STDERR to STDOUT if yo uare also planning to redirect STDOUT to a file. The order in which things are done affects the outcome. These are not the same: # Redirect STDOUT to file, and STDERR to file command >/tmp/command.out 2>&1 # Redirect STDOUT to file, and STDERR to screen (as STDOUT) command 2>&1 >/tmp/command.out The important thing to remember is that 2>&1 is redirecting to what STDOUT is currently pointing to, not redirecting to STDOUT itself.
- scbrg 13y agoThank you for posting that. I always knew the two behaved differently, and how - but I never really understood why. Your final line cleared that up.
- TorKlingberg 13y agoRecent version of bash support the (much nicer) csh syntax: command >& /tmp/command.out
- kbenson 13y agoI wanted to mention that in the original post, but I can never remember the syntax and was rushed. :(