Wednesday, December 5, 2007

Linux I/O Redirection

# The following command saves stdout and stderr to the files "out.txt" and "err.txt", respectively.
[root@server /root]# ./cmd 1>out.txt 2>err.txt

# The following command appends stdout and stderr to the files "out.txt" and "err.txt", respectively.
[root@server /root]# ./cmd 1>>out.txt 2>>err.txt

# The following command functions similar to the above two commands, but also copies stdout and stderr to the files "stdout.txt" and "stderr.txt", respectively.
[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3\
|tee stderr.txt) 3>&1 1>&2 2>&3) 1>out.txt 2>err.txt

No comments: