Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I am trying to insert some text in a file in the following way

sudo echo "abc-abc/abc/abc" >> /etc/portage/make.conf

but it give me the error Permission denied

although I am using sudo command

can any body help me in this regards

share|improve this question
add comment

marked as duplicate by jasonwryan, Anthon, rahmu, enzotib, Stephane Chazelas Aug 6 '13 at 10:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 1 down vote accepted

Sudo just executes the first command, in your case " echo "abc-abc/abc/abc" ".

So the rest of the command (writing in /etc/portage/make.conf) will be executed in user mode.

You just have to modify the permissions on the file using chmod.

share|improve this answer
    
Let's be serious, you don't want to chmod a file to modify it when you have sudo access. –  Stephane Chazelas Aug 7 '13 at 11:08
add comment

In that command line, your shell opens the /etc/portage/make.conf in append mode, makes it the stdout of a new process and runs sudo in that new process. It's not sudo nor echo that open the file, it's your shell which is running with your credentials.

You'd need the file to be opened by the command started as root. So it could be:

sudo sh -c 'echo "abc-abc/abc/abc" >> /etc/portage/make.conf'

Or:

echo "abc-abc/abc/abc" | sudo tee -a /etc/portage/make.conf > /dev/null
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.