Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Accessing microphone



On 08/05/06, Dave M G <martin@example.com> wrote:

dave@example.com:~$ sudo generate-modprobe.conf > /etc/modprobe.conf
bash: /etc/modprobe.conf: Permission denied

How can I be denied permission if I'm doing it with "sudo"? It didn't
even ask me for my password?

This is a great example to illustrate how a shell works. When you type
the above command, the shell interprets it as:

1. Run the "sudo generate-modprobe.conf" command, then
2. Redirect its output to the "/etc/modprobe.conf" file

sudo ensures that the "generate-modprobe.conf" file runs as root, but
the shell, which is redirecting the output of the command to a file,
is still running as a non-privileged user, namely, you.

There are (at least) two ways around this. One would be to redirect
the output of the command to a file to which you have write
permission, then move it to its proper location, i.e.

generate-modprobe.conf > /tmp/modprobe.conf
sudo mv /tmp/modprobe.conf /etc/modprobe.conf

Or, you could use the magic of tee(1) and Unix pipes:

generate-modprobe.conf | sudo tee /etc/modprobe.conf

Read the manpage of tee(1) to see why this works. :)

-Josh

Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links