Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append the output to a file?

People also ask

Which command is used to append in a file?

How do I use the cat command to append data to a file? You can use the cat command to append data or text to a file. The cat command can also append binary data. The main purpose of the cat command is to display data on screen (stdout) or concatenate files under Linux or Unix like operating systems.

How do I append to a file in bash?

How to append to file in Bash. To make a new file in Bash, you normally use > for redirection, but to append to an existing file, you would use >> .


Use >> to append:

command >> file

Yeah.

command >> file to redirect just stdout of command.

command >> file 2>&1 to redirect stdout and stderr to the file (works in bash, zsh)

And if you need to use sudo, remember that just

sudo command >> /file/requiring/sudo/privileges does not work, as privilege elevation applies to command but not shell redirection part. However, simply using tee solves the problem:

command | sudo tee -a /file/requiring/sudo/privileges