If the user has changed their prompt to some other format we need to try something else. The
who command will give us the information we are looking for.
The output from
who gives you the name of the current user, the terminal they are logged in at, the date and time when they logged in. If it is a remote session, it also tell us where they are logged in from.
By comparison, the
whoami command provides a very pithy answer:
You can get the same one-word answer by echoing the
$USER environment variable to the screen.
The one-letter command
w requires less typing and provides more information.
w command provides us with the user name which is what we wanted, and a bonus set of data for that user. Note that if there are multiple users logged into the Linux system, the
w command will list them all. You’d need to know which terminal the user you were interested in had logged in on. If they’ve logged directly onto the Linux computer itself, that’ll be pts/o, so look for :0 in the output from
w command provides the boot time, uptime and average load for the previous five, ten and fifteen minutes, and the following information regarding the current user.
- USER: The user name.
- TTY: The type of terminal they are logged in at. This will usually be a pts (a pseudo-teletype). :0 means the physical keyboard and screen connected to this computer.
- FROM: The name of the remote host if this is a remote connection.
- LOGIN@: The time at which the user logged in.
- IDLE: Idle time. This shows ?xdm? in the screenshot because we’re running under an X-windows Display Manager, which does not provide that information.
- JCPU: Joint CPU time, this is the CPU time used by all processes that have been attached to this tty. In other words, the total CPU time of this user in this logged in session.
- PCPU: Process CPU time, this is the CPU time used by the current process. The current process is named in the WHAT column.
- WHAT: The command line of this user’s current process.
Now that we know who this user is, we can obtain more information about them. The
id command is a good place to start. Type
id, a space, the name of the user and press enter.
This gives us their user ID (uid), group ID (gid) and the groups they’re a member of. A less cluttered display of the groups can be obtained by using the
groups dave Source