Home arrow FreeBSD Tips arrow Sudo Tips
Sudo Tips PDF
Monday, 05 May 2008
If you need to use sudo and you need to redirect the result into a file with write permission only for root, you will get the following error:

sudo echo '10.0.0.1    local.freebsdonline.com       local' >> /etc/hosts
cannot create /etc/hosts: Permission denied

Or if you need to run shell commands, say a simple change directory:

 $ pwd
/home
$ sudo cd /usr
$ pwd
/home

The command goes without an error buf after the command runs you realize that it did not work. 

This is due to the fact that you are trying to gain rigths for a shell that is alread started.

The workaround for this is to run the commands in a sub-shell like this:

sudo sh -c "echo '10.0.0.1     local.freebsdonline.com   local' >> /etc/hosts" 

 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?