Home>Article>Operation and Maintenance> How to use the whoami command in linux

How to use the whoami command in linux

小老鼠
小老鼠 Original
2024-04-18 16:18:14 1184browse

The whoami command is used to display the username and group of the currently logged in user. Syntax: whoami. Output: Current username. Variants: whoami -u (username only), whoami -g (group only), whoami -p (PID only). Built-in command used to determine the identity of the user when running the command.

How to use the whoami command in linux

whoami command in Linux

What is the whoami command?

The whoami command is a command used to display the username and group of the currently logged in user in a Linux system.

How to use the whoami command?

The syntax of the whoami command is very simple:

whoami

Command output

After executing the whoami command, you will see the following output:

当前用户名

You can also get additional information using the following variations:

  • whoami -u: Show only the current username.
  • whoami -g: Only displays the current user's belonging groups.
  • whoami -p: Only displays the process ID (PID) of the current user.

Example

The following example shows how to use the whoami command:

$ whoami alice

This means that the current logged in user name is alice.

Additional Information

  • The whoami command is a built-in command, which means it does not require any external program.
  • The whoami command is useful for determining who you are when running commands on your system.
  • The whoami command can also be used as a simple way to check a user's identity in a script.

The above is the detailed content of How to use the whoami command in linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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