27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

who<br />

Show all users logged on to the system.<br />

bash$ who<br />

bozo tty1 Apr 27 17:45<br />

bozo pts/0 Apr 27 17:46<br />

bozo pts/1 Apr 27 17:47<br />

bozo pts/2 Apr 27 17:49<br />

The −m gives detailed information about only the current user. Passing any two arguments to who is<br />

the equivalent of who −m, as in who am i or who The Man.<br />

bash$ who −m<br />

localhost.localdomain!bozo pts/2 Apr 27 17:49<br />

whoami is similar to who −m, but only lists the user name.<br />

bash$ whoami<br />

bozo<br />

w<br />

Show all logged on users and the processes belonging to them. This is an extended version of who.<br />

The output of w may be piped to grep to find a specific user and/or process.<br />

bash$ w | grep startx<br />

bozo tty1 − 4:22pm 6:41 4.47s 0.45s startx<br />

logname<br />

Show current user's login name (as found in /var/run/utmp). This is a near−equivalent to<br />

whoami, above.<br />

bash$ logname<br />

bozo<br />

bash$ whoami<br />

bozo<br />

However...<br />

bash$ su<br />

Password: ......<br />

su<br />

sudo<br />

bash# whoami<br />

root<br />

bash# logname<br />

bozo<br />

Runs a program or script as a substitute user. su rjones starts a shell as user rjones. A naked su<br />

defaults to root. See Example A−16.<br />

Runs a command as root (or another user). This may be used in a script, thus permitting a regular user<br />

to run the script.<br />

Chapter 13. System and Administrative Commands 215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!