Issue
To redirect standard output to a truncated file in Bash, I know to use:
cmd > file.txt
To redirect standard output in Bash, appending to a file, I know to use:
cmd >> file.txt
To redirect both standard output and standard error to a truncated file, I know to use:
cmd &> file.txt
How do I redirect both standard output and standard error appending to a file? cmd &>> file.txt did not work for me.
Solution
cmd >>file.txt 2>&1
Bash executes the redirects from left to right as follows:
>>file.txt: Openfile.txtin append mode and redirectstdoutthere.2>&1: Redirectstderrto "wherestdoutis currently going". In this case, that is a file opened in append mode. In other words, the&1reuses the file descriptor whichstdoutcurrently uses.
Answered By - Alex Martelli Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.