This is the shell command that results in "Permission denied" when I'm trying to append the data in a file to another file with sudo:
sudo cat add_file >> /etc/file
The file at /etc/file
is owned by root
(i.e. me) and its permissions are rw-r--r--
. Should I become root
for a moment to make it work or is there a workaround for sudo
?
Similar approach to @gniourf_gniourf answer, but using
ex
:which is equivalent to
vi
/vim
Ex-mode (-e
).This in-place edit example is simple, safe and convenient approach, because it doesn't use any shell piping, FIFOs or shell within the shell workarounds.
To boost performance for scripting purposes, consider using silence mode (
-s
).Run
bash
assudo
:Try doing this instead :
It's lighter than running bash or
sh -c command
A funny possibility is to use
ed
(the standard editor):I know I won't get upvoted for this wonderful answer, but I wanted to include it here anyway (because it's funny). Done!
try
or
You are trying to write the result of the command
sudo cat add_file
to the file /etc/file. And apparently you don't have that right.man sudo
gives that example :So you should try :
sudo sh -c "cat add_file >> /etc/file"