Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

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.

share|improve this question

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.

up vote 1 down vote accepted

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"
share|improve this answer
Thank you so so much. – Bodhidarma Feb 9 '12 at 22:13

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.

share|improve this answer

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
share|improve this answer

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