Getting Full User Name
How do I look up my full user name in Ubuntu? I want this information to propagate to the environment variables GIT_AUTHOR_NAME
and GIT_COMMITTER_EMAIL
.
Solution 1:
These fields in the /etc/passwd
file are called GECOS fields. Unfortunately, I cannot find a single command to get this single field such as the full name. I believe this cannot be done without using shell scripting. Below are two approaches.
-
Parse
passwd
directly:getent passwd $USER | cut -d ':' -f 5 | cut -d ',' -f 1 Gert van Dijk
-
Use of
finger
finger -m $USER | head -n 1 | sed 's/\(.*\)Name\:\s\(.*\)$/\2/g' Gert van Dijk
Related question on SO: What's the easiest way to get a user's full name on a Linux/POSIX system?
For programming in C, this is more elegant by using getpwnam()
.
But really, for use in Git for a single user do:
git config --global user.name "Your Full Name"
git config --global user.email "[email protected]"