开发者

How to append the output to a file?

开发者 https://www.devze.com 2023-02-17 06:51 出处:网络
How can I do something like command > file in a way that it appends to the fi开发者_如何学Pythonle, instead of overwriting?Use >> to append:

How can I do something like command > file in a way that it appends to the fi开发者_如何学Pythonle, instead of overwriting?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消