Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user name from the command line on different platforms

Is there a way in MATLAB to get the user name of the user that started the session?

I am interested in solutions for Windows, Linux and Mac OSX. I imagine that if the solutions are platform-specific, both solutions can be integrated as follows:

if ispc
    user_name = % method 1
elseif isunix
    user_name = % method 2
elseif ismac
    user_name = % method 3
end
like image 451
Amelio Vazquez-Reina Avatar asked Jul 26 '12 15:07

Amelio Vazquez-Reina


People also ask

Which command is used to find username?

In the box, type cmd and press Enter. The command prompt window will appear. Type whoami and press Enter. Your current user name will be displayed.

How do I print a username in Linux?

a] $USER – Current user name. b] $USERNAME – Current user name. c] id command – Print current user name. d] whoami command – Show current user name.

How do I find my username in Linux terminal?

To quickly reveal the name of the logged in user from the GNOME desktop used on Ubuntu and many other Linux distributions, click the system menu in the top-right corner of your screen. The bottom entry in the drop-down menu is the user name.

What is the command to list all users in Linux?

Use the “cat” command to list all the users on the terminal to display all the user account details and passwords stored in the /etc/passwd file of the Linux system. As shown below, running this command will display the usernames, as well as some additional information.


1 Answers

How about using Java (works on all platforms supported by MATLAB):

user_name = java.lang.System.getProperty('user.name')
like image 129
Amro Avatar answered Nov 04 '22 13:11

Amro