logname Command in Linux



logname command in Linux is a simple yet useful utility that displays the login name of the user who is currently logged in. When you run logname, it returns the name of the user that started the current session. This can be pretty useful in scripts or when performing administrative tasks since it helps identify the user content under which commands are being executed.

Unlike whoami, which shows the effective user name, logname shows the actual login name. It's a quick way to verify the user identity in multi-user environments.

Table of Contents

Here is a comprehensive guide to the options available with the logname command −

Syntax of logname Command

The general syntax to use the logname command on Linux is as follows −

logname [options]

Where,

  • [options] are various flags that can modify the behavior of the logname

Note − The command logname typically does not require any options and is generally used in its basic form. Options like --help and --version can be used to display helpful information or version details, but they're rarely needed for everyday use.

How to Use logname Command in Linux?

As previously mentioned, the logname is a straightforward command that requires no additional options or parameters. To use it on a Linux system, simply type logname and press Enter to see the login name of the user who initiated the current session.

logname
logname Command in Linux1

Conclusion

The logname command in Linux is a simple yet effective utility for displaying the login name of the current user. When executed, it returns the name of the user who started the session, which is particularly useful in scripts and administrative tasks to identify the user context.

In this turtorial, we covered the syntax and provided practical examples to help you understand how to use the command logname effectively. With this knowledge, you can easily identify the login name of users and manage tasks efficiently on your Linux system.

Advertisements