Get current user’s username in Linux

You can use the command:

id -un

To get the current user’s username in Linux. Handy if you are shell scripting and need to know who is logged in dynamically as part of your script.