How can I do something like command > file
in a way that it appends to the file, instead of overwriting?
如何以附加到文件的方式执行命令>文件之类的操作,而不是覆盖文件?
3 个解决方案
#1
186
Use >>
to append:
使用> >添加:
command >> file
#2
95
Yeah.
是的。
command >> file
to redirect just stdout of command
.
命令>>文件重定向仅stdout命令。
command >> file 2>&1
to redirect stdout and stderr to the file (works in bash, zsh)
命令>>文件2>&1将stdout和stderr重定向到文件(在bash、zsh中工作)
And if you need to use sudo
, remember that just
如果你需要使用sudo,请记住
sudo command >> /file/requiring/sudo/privileges
does not work, but simply using tee
solves the problem:
sudo命令>> /file/ require /sudo/privileges不起作用,但是仅仅使用tee就可以解决问题:
command | sudo tee -a /file/requiring/sudo/privileges
命令| sudo tee -a /file/ require /sudo/privileges
#3
-2
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
您可以附加带有>>符号的文件。它在我们正在使用的文件的最后插入内容。如果文件让它的名字是myfile包含xyz那么cat >> myfile abc ctrl d
after the above process the myfile contains xyzabc.
在上述过程之后,myfile包含xyzabc。
#1
186
Use >>
to append:
使用> >添加:
command >> file
#2
95
Yeah.
是的。
command >> file
to redirect just stdout of command
.
命令>>文件重定向仅stdout命令。
command >> file 2>&1
to redirect stdout and stderr to the file (works in bash, zsh)
命令>>文件2>&1将stdout和stderr重定向到文件(在bash、zsh中工作)
And if you need to use sudo
, remember that just
如果你需要使用sudo,请记住
sudo command >> /file/requiring/sudo/privileges
does not work, but simply using tee
solves the problem:
sudo命令>> /file/ require /sudo/privileges不起作用,但是仅仅使用tee就可以解决问题:
command | sudo tee -a /file/requiring/sudo/privileges
命令| sudo tee -a /file/ require /sudo/privileges
#3
-2
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
您可以附加带有>>符号的文件。它在我们正在使用的文件的最后插入内容。如果文件让它的名字是myfile包含xyz那么cat >> myfile abc ctrl d
after the above process the myfile contains xyzabc.
在上述过程之后,myfile包含xyzabc。