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 '    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
$ sudo cd /usr
$ pwd

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 '     local.freebsdonline.com   local' >> /etc/hosts" 

< Prev   Next >

Other BSD Systems





Best BSD firewall?