Cheat Sheet #day55 - whoami
Cloud Tuned
1 min read
whoami
Command Cheatsheet
The whoami
command is used to display the current logged-in user’s username. It is a simple yet useful command, particularly for scripting and troubleshooting.
Syntax
whoami
Description
- Purpose: Returns the username of the current user.
Examples and Use Cases
Display Current User
whoami
- Outputs the username of the currently logged-in user (e.g.,
john
).
Use in Scripts
You can use whoami
in scripts to dynamically reference the current user. For example:
#!/bin/bash
echo "Current user is: $(whoami)"
- This script will print the current user’s name.
Check User Privileges
Combine whoami
with id
to display user and group information:
whoami
id -u $(whoami)
- Outputs the user ID of the current user.
Options
whoami
has no options. It simply returns the username.
Additional Information
Man Page: For more details, you can refer to the
whoami
man page:man whoami
This cheatsheet provides a quick reference to the whoami
command. Let me know if you need more information or additional examples!
0
Subscribe to my newsletter
Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by