Note: the following examples assume a properly configured security
policy.
To get a file listing of an unreadable directory:
$ sudo ls /usr/local/protected
To list the home directory of user yaz on a machine where the file
system holding ~yaz is not exported as root:
$ sudo -u yaz ls ~yaz
To edit the index.html file as user www:
$ sudoedit -u www ~www/htdocs/index.html
To view system logs only accessible to root and users in the adm
group:
$ sudo -g adm more /var/log/syslog
To run an editor as jim with a different primary group:
$ sudoedit -u jim -g audio ~jim/sound.txt
To shut down a machine:
$ sudo shutdown -r +15 "quick reboot"
To make a usage listing of the directories in the /home partition.
Note that this runs the commands in a sub-shell to make the cd and
file redirection work.
$ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"