Name

whoami — stdin  stdout  - file  -- opt  --help  --version

Synopsis

whoami

The whoami command prints the name of the current, effective user. This may differ from your login name (the output of logname) if you’ve used the sudo command. The following example distinguishes whoami from logname. In normal situations, they both print your username:

logname
smith
➜ whoami
smith

When you become the root user via sudo, then effectively you are the root user, and whoami indicates this:

sudo logname
smith
➜ sudo whoami
root

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.