Redirect all shell output to a single file

From LinuxReviews
Jump to: navigation, search

Shell commands send two kinds of text to terminals: standard output (stdout) and standard error (stderr).

stdout are captured as 1,

 ./shellscript 1>>foo

stderr as 2,

 ./shellscript 2>>foo

If you want to send all output to a log file then use the following:

./shellscript >> /path/to/logfile 2>&1

2>&1 redirects standard error messages to standard out, which allows you to capture both to a single file.

Note that >> opens a file and writes to the end of it, > zeroes the file if it exists and then redirects to it.

Personal tools
hardware tests
Privacy policy
linux events


linux newz | random page | poetry | free blog