Linux command 'w' - how is this as command written in Android shell? I am searching for similiar commands in Android shell - as they are used in Linux like these commands - what can I type in Android terminal for :


  w
  
  who
  
  whoami


?

Thank you.
Linux commands w and who read login information from file /var/run/utmp. Traditional Linux sysV login records/logs like utmp, wtmp, btmp and lastlog are set and read by some programs that make use of GNU libc (the most commonly used C library on Linux distros) and other libc's. These files contain information about currently and previously logged-in users.

However there is no concept of Linux console login on Android as it isn't designed for multiple user logins. Virtual terminals are disabled on Android by default, init doesn't start getty, and hence there is no login, no login manager (like logind), no shell at startup and no user sessions, and therefore no login files. Android boots directly to GUI. Other CLI programs like sshd that read/write these login files are also not part of Android. So Android's Bionic libc neither provides the functions of utmp.h, nor filesystem hierarchy contains /var/log or /var/run. However if a program linked against standard Linux libc's is used on Android, it will try to access these login files. But if a program - like w, who, users, last and lastlog - is totally dependent on these files, it simply won't work. You can use busybox such as yashdsaraf's to get all these commands on Android.

Linux command whoami gets the (effective) UID of process by making syscall geteuid directly to kernel and then on Linux , if possible, resolves ID to name using name resolution mechanisms like directly from /etc/passwd, /etc/group or through NSS, NSCD etc. id command additionally does getgid and getgroups as well. So these commands work on Android as expected and - along with other similar tools logname and groups - are part of toybox; Android's choice for all-in-one Linux command line tool.
Bionic libc's wrapper functions (that apps actaully use through Android APIs to get UID) and kernel syscalls are also identical as is the case with other libc's:

~# nm -C /system/lib64/libc.so | grep geteuid$
0000000000070d58 T geteuid
~# grep geteuid$ /proc/kallsyms
0000000000000000 T sys_geteuid


RELATED: HOW TO SETUP LINUX LOGIN ENVIRONMENT ON ANDROID