logname

prints the user's login name

TLDR

Print login name
$ logname

SYNOPSIS

logname [options]

DESCRIPTION

logname prints the name of the user who originally logged in on the controlling terminal. It uses the `getlogin` system call, which determines the login name from the session's utmp record rather than from environment variables (which cannot be trusted).Unlike whoami, which reports the current effective user, logname keeps showing the original login name after su or sudo switch the effective user.

PARAMETERS

--help

Display help information.
--version
Display version information.

INSTALL

sudo apt install coreutils
sudo dnf install coreutils
sudo pacman -S coreutils
sudo apk add coreutils
sudo zypper install coreutils
brew install coreutils
nix profile install nixpkgs#coreutils

CAVEATS

Fails with "no login name" when there is no controlling terminal (for example in some cron jobs or daemons). Differs from whoami after su. POSIX standard command.

HISTORY

logname is a traditional Unix command from POSIX, showing the name used to log into the system.

SEE ALSO

whoami(1), who(1), id(1)