Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some VM stuff set up in my mamp instance, I'm using wp-cli in a bash to install wordpress instances, I wanted to add to this script a command to edit the hosts file based on a var.

sudo echo -e "\timtest\n" >> /etc/hosts

-bash: /etc/hosts: Permission denied
share|improve this question
See my answer to "How do I use sudo to redirect output to a location I don't have permission to write to?" from Stack Overflow. – Cristian Ciupitu Jun 9 '14 at 17:22
up vote 2 down vote accepted

I think the >> gets associated with the sudo command, not with the echo command you're trying to run. You run echo with root perms, but the shell associates the >> with the sudo, no special perms.

I'd try it more like:

sudo bash -c 'echo -e "\timtest\n" >> /etc/hosts'

(with a test run as sudo bash -c 'echo -e "\timtest\n" >> /etc/' for testing)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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