In command line platforms online, like for instance the one on Codecademy, when I run

for cmd in w who whoami id
    echo $cmd
    echo =========================
    echo "             "

I get

00:52:54 up 8 days, 14:10,  0 users,  load average: 3.78, 2.98, 2.69      
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT       


uid=1000(ccuser) gid=1000(ccuser) groups=1000(ccuser)     

Note that only whoami and id output something. When I run the same thing on my computer, I see similar results for all commands.

Why doesn't Codecademy display the user for w and who? What's different about these commands?

  • id reports
    • the current credentials of its own process; or
    • the credentials of a named user, as read out of the system account database.
  • whoami reports the current credentials of its own process.
  • who and w report the active login sessions table from the login database.

BSD doco notes that whoami does a subset of the job of id, and that id renders it obsolete.

A system does not have to have an active login sessions table. On Linux operating systems and on the BSDs, if the table has not been created at bootstrap, or has been deleted since, the system will operate without one. Logging in and out does not implicitly create it on Linux operating systems, moreover.

Furthermore, the table need not be readable by unprivileged users and neither the who nor the w command will report this as an error.

Further reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.