How to append the output to a file?

▼魔方 西西 提交于 2020-01-25 08:07:53

问题


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


回答1:


Use >> to append:

command >> file



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/58651250/bash-read-and-print-multiple-files-using-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!