Home > System Tutorial > LINUX > Usage and difference between whoami and who am i commands in Linux

Usage and difference between whoami and who am i commands in Linux

WBOY
Release: 2024-02-18 23:15:07
Original
1401 people have browsed it

The usage and difference of whoami and who am i commands in Linux require specific code examples

In Linux systems, whoami and who am i are two commonly used commands, used to view the users of the currently logged in user name. Although their functionality is similar, there are some differences in usage and output results. This article will introduce the usage and differences of these two commands and provide specific code examples.

  1. whoami command

The whoami command is used to display the username of the currently logged in user. It doesn't require any parameters, just execute the command directly.

Sample code:

$ whoami
output: username

In the above sample code, after executing the whoami command, the system will return the username of the currently logged in user.

  1. who am i command

The who am i command is used to display the username of the currently logged in user, but it can be used with other parameters. The most commonly used parameter is -f (full name), which is used to display the full name of the currently logged in user.

Sample code:

$ who am i -f
output: username Full Name

In the above sample code, execute the who am i command and add the -f parameter After that, the system will return the username and full name of the currently logged in user.

  1. Difference

The main difference lies in the output content and usage method.

The whoami command only displays the user name of the currently logged in user, while the who am i command can also display other information, such as the full name, in addition to the user name.

In terms of usage, the whoami command does not require any parameters and can be executed directly, while the who am i command can be used with other parameters, such as the -f parameter to display the full name.

Sample code:

$ whoami
output: username

$ who am i
output: username pts/0 2020-01-01 10:00 (:0)

$ who am i -f
output: username Full Name

  1. Summary

Although whoami and who am i command functions Similar, both are used to display the username of the currently logged in user, but there are some differences in usage methods and output results. The whoami command directly displays the user name, while the who am i command can be used with other parameters, such as the -f parameter to display the full name.

I hope this article will help you understand the usage and difference between whoami and who am i commands in Linux systems. In actual use, select the appropriate command according to your needs to view the information of the currently logged in user.

The above is the detailed content of Usage and difference between whoami and who am i commands in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template