The logname
command is used to print the name of the current terminal logged in user. This command is useful when you need to quickly determine the username of the user logged into a terminal session.
To use this command, simply open a terminal and type logname
. The output will be the name of the user currently logged into that terminal session.
$ logname
johndoe
Use Cases
- Quickly determine the username of the user logged into a terminal session.
- Use in scripts to perform actions based on the current user.
Options
The logname
command has no options.
Troubleshooting Tips
If the logname
command does not return any output, it may be because no user is currently logged into the terminal session. Ensure that a user is logged in before running this command.
Notes
- The
logname
command is only useful for determining the username of the user logged into a terminal session. To determine the username of the user running a script or command, use thewhoami
command instead. - This command is available on most Linux distributions and does not require any special permissions to run.