Mailinglist Archive: opensuse (1445 mails)

< Previous Next >
Re: [opensuse] bash - howto sudo echo X >> Y (sed?)
On 03/11/2012 01:27 PM, David C. Rankin wrote:

I have an interesting question. I have a file that I need to append
information to that is owned by root. Initially I wanted to use echo:

sudo echo "X" >> y.txt

But, of course the echo has root privileges, but the redirection does not.
then I though about sed. It works, but how do I tell sed to 'append to end of

The last word in the existing file is custompkgs, but that isn't guaranteed
stay that way. As it sits, I can:

sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#'

How can I omit searching for a word and just tell sed to append at end of

Or, how can I use echo or cat to do the same thing, but overcome the lack of
privilege on the >> ?

sudo bash -c "echo testing >>/root/test"

The answer is in "man sudo"

Jim Cunning

To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >