How can I do something like command > file
in a way that it appends to the file, instead of overwriting?
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Invoking Mirth Connect CLI with Powershell script
- Error building gcc 4.8.3 from source: libstdc++.so
Use
>>
to append: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.
Yeah.
command >> file
to redirect just stdout ofcommand
.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 justsudo command >> /file/requiring/sudo/privileges
does not work, but simply usingtee
solves the problem:command | sudo tee -a /file/requiring/sudo/privileges