2 Methods to Get Username of Current User on Linux

2 Methods to Get Username of Current User on Linux

In Linux systems, many administrative tasks and automation scripts depend on knowing which user is currently executing a command. This information is often used for permission handling, logging, environment configuration, and debugging unexpected behavior in multi-user systems. This tutorial provides 2 methods how to get username of current user on Linux.

Method 1 - id command

The id command is commonly used to display user and group information. By using the -un option, it returns only the username of the current user.

id -un

Example output:

john

Method 2 - whoami command

The whoami is another standard utility that directly prints the username of the current user.

whoami

Leave a Comment

Cancel reply

Your email address will not be published.