Possible Duplicate:
Redirecting stdout to a file you don't have write permission on

I'm trying to install drupal according to the instructions given in this tutorial: http://how-to.linuxcareer.com/how-to-install-drupal-7-on-ubuntu-linux and am stuck on a step:

$ cd /etc/apache2/sites-available
$ sudo sed 's/www/www\/drupal/g' default > drupal
bash: drupal: Permission denied

The permissions for /var/www/drupal are set to 777.

marked as duplicate by Gilles, Michael Mrozek Feb 10 '12 at 15:07

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.


The tutorial does not use sudo and requires a root shell. You can get a root shell with sudo -i.

In case you prefer sudo, the redirection is handled by the shell and not by the sudo command. So you can't create a file in /etc/apache2/sites-available by directing the output as you did. According to the sudo manual, you should use a subshell like:

$ cd /etc/apache2/sites-available
$ sudo sh -c "sed 's/www/www\/drupal/g' default > drupal"

Apparently the permissions on /etc/apache2/sites-available are not 777, and that's where you're writing your output to. The redirection is processed separately from the sudo, and you don't have write permissions there. Now, there's nothing about /var/www/drupal there, is that where you're trying to write to? If so you can either use su -c "sed 's/www/www\/drupal/g' default > /var/www/drupal" or sed 's/www/www\/drupal/g' default | sudo tee drupal.


First, you are not at /var/www/drupal/. You are trying to create the file drupal at /etc/apache2/sites-available/. If you want the file to be created at /var/www/drupal:

sed 's/www/www\/drupal/g' default >/var/www/drupal/drupal


sed 's/www/www\/drupal/g' default | sudo tee drupal

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