When sudo cat a
is run, file a's contents were read and printed on the stdout with sudo
privileges. The redirection of the text was handled by the shell and would be appended to file b (since >>
was used). In this particular case it seems that the file didn't have permission to be modified by non-superuser.
Although running shell as root using sudo su
, sudo -i
or sudo -s
seems to be a good idea to overcome this limitation, but it is not suggested. It might happen that shell was running with sudo
privileges and unknowingly without exiting the root shell, some other command is used. And if that command is mistyped, it can cause serious harm to the system.
In such cases, cat
's output can be piped and tee
can be used. It is a utility which read the input from standard input and outputs to file and standard output. Since you want to append the file, -a
option can be used. Therefore, the command will look like:
sudo cat f84e19a2f44c6386.crt gd_bundle-g2-g1.crt | sudo tee -a coolexample.crt
I assumed that f84e19a2f44c6386.crt and gd_bundle-g2-g1.crt didn't have permissions to be read by normal users.