A tip for users of sudo

I use sudo alot (like most debian based linux users), something that often catches me out is redirection.

This is coz sudo only applys to the first command, any following commands or redirection are performed as the orignal user.. so to get around this, lets run all the required commands/redirection in 1 command.

sudo sh -c 'ls -al /root/ > /test.out'

This basically starts a shell using sudo.. then runs the command passed to the -c option, then finishes and your back to your typical shell.

You can also do:

sudo bash

This will result in a shell stared with sudo… and you are now in it, so all following commands will be done with sudo rights