How do I get the name of the active user via the command line in OS X?

as 'whoami' has been obsoleted, it's probably more forward compatible to use:

id -un

If you'd like to display the full name (instead of the username), add the -F flag:

$ id -F
Andrew Havens

whoami

EDIT

The whoami utility has been obsoleted by the id(1) utility, and is equivalent to id -un. The command id -p is suggested for normal interactive use.


I'm pretty sure the terminal in OS X is just like unix, so the command would be:

whoami

I don't have a mac on me at the moment so someone correct me if I'm wrong.

NOTE - The whoami utility has been obsoleted, and is equivalent to id -un. It will give you the current user


Via here

Checking the owner of /dev/console seems to work well.

stat -f "%Su" /dev/console