How to append the output to a file?

2019-01-30 06:01发布

How can I do something like command > file in a way that it appends to the file, instead of overwriting?

3条回答
相关推荐>>
2楼-- · 2019-01-30 06:13

Use >> to append:

command >> file
查看更多
Rolldiameter
3楼-- · 2019-01-30 06:29

you can append the file with >> sign. It insert the contents at the last of the file which we are using.e.g if file let its name is myfile contains xyz then cat >> myfile abc ctrl d

after the above process the myfile contains xyzabc.

查看更多
何必那么认真
4楼-- · 2019-01-30 06:31

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, but simply using tee solves the problem:

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

查看更多
登录 后发表回答