Linux distributions stores different information about the user accounts. The User Full Name is also stored for the users and located inside the /etc/passwd file. The user’s full name is requested during user account creation. But it can be changed later in different ways. The user’s full name can be changed via a command-line interface or GUI. In this tutorial, we examine command line or GUI methods to change a user’s full name in Linux.
The user’s full name is stored inside the /etc/passwd and there are different ways to show the user’s full name. The cat command can be used to print the passwd file which also shows the user’s full name.
The native and easiest way to change user’s full name is the chfn command. The chfn command -f option is used to set specified user full name. The username is provided as a parameter to specify the user which full name will be set. In the following example, we set the user ismail name as “İsmail Baydan”.
$ chfn -f "İsmail Baydan" ismail
Another command to set or change user full name is the usermod command. The user full name is provided with the -c option and also the username is provided. In the following example, we set the user ismail name as “İsmail Baydan”.
$ usermod -c "İsmail Baydan" ismail
The user full name is stored inside the /etc/passwd file. This file can be opened with an text editor and related user full name can be changed and saved as the last step. The /etc/passwd file should be opened with the administrator privileges like root or by using the sudo command.
Another way to change user’s full name is using the GUI which can be GNOME, KDE, XFCE, etc. Just open the Settings tool and navigate to the Users tab from the left pane. Then click on the pen image which edits the user’s full name.
Just edit the user’s full name and click different locations to save the new full name.
I could grep through /etc/passwd but that seems onerous. ‘finger’ isn’t installed and I’d like to avoid that dependency. This is for a program so it would be nice if there was some command that let you just access user info.
You don’t specify a programming language, so I’ll assume you want to use the shell; here’s an answer for Posix shells.
Two steps to this: get the appropriate record, then get the field you want from that record.
First, getting the account record is done by querying the passwd table:
$ user_name=foo $ user_record="$(getent passwd $user_name)" $ echo "$user_record" foo:x:1023:1025:Fred Nurk. /home/foo:/bin/bash
For hysterical raisins, the full name of the user is recorded in a field called the “GECOS” field; to complicate matters, this field often has its own structure with the full name as just one of several optional sub-fields. So anything that wants to get the full name from the account record needs to parse both these levels.
$ user_record="$(getent passwd $user_name)" $ user_gecos_field="$(echo "$user_record" | cut -d ':' -f 5)" $ user_full_name="$(echo "$user_gecos_field" | cut -d ',' -f 1)" $ echo "$user_full_name" Fred Nurk
Your programming language probably has a library function to do this in fewer steps. In C, you’d use the ‘getpwnam’ function and then parse the GECOS field.
I’m looking to find out the logged in user’s real (full name) to avoid having to prompt them for it in an app I’m building. I see the finger command will output a columned list of data that includes this and was wondering if it makes sense to grep through this or is there an easier way? None of the switches for finger that I’ve found output just the real name. Any thoughts would be much appreciated.
Right on Beta, that worked beautifully. Do you think that this is safe if there is more than one logged in user? Specifically does your sed magic above return all real name’s or just the first one it encounters? Thanks!
Or: finger blah | grep Name | awk -F «Name:» ‘
getent passwd `whoami` | cut -d : -f 5
( getent is usually preferable to grepping /etc/passwd ).
getent passwd "$USER" | cut -d: -f5 | cut -d, -f1
This first fetches the current user’s line from the passwd database (which might also be stored on NIS or LDAP)
In the fetched line, fields are separated by : delimiters. The GECOS entry is the 5th field, thus the first cut extracts that.
The GECOS entry itself is possibly composed of multiple items — separated by , — of which the full name is the first item. That’s what the second cut extracts. This also works if the GECOS entry is lacking the commas. In that case the whole entry is the first item.
You can also assign the result to a variable:
fullname=$( getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 )
Or process it further directly:
echo "$( getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 )'s home is $HOME."
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
How do i find my system login username in Ubuntu 20.04.3 LTS ?
Just type in whoami at the command line. Or if you need it in a script variable, try something like user=$(whoami) (then echo $user or whatever).
Use this solution if you didn’t encrypt your home directory.
Do you still have the installation media(LiveCD/USB) from which you installed Ubuntu? Boot from it and select Try Ubuntu.
Go to Files and then, you will see you already installed Ubuntu partition. Click on it, it will mount.
Go to /home. Here you will see a list of all users on the system that you have created.
To jog your memory, however, what is your name? Did you enter the same name while installing Ubuntu? Do you recall the name that was displayed on the login prompt where you entered your password? Ubuntu by default sets the username as your first name in lowercase.
AdblockExample; name= John Doe, automatically set username= john