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.

  • What do you mean by full user name?
    – Symin
    Feb 2 '13 at 12:05
  • Like "Peter Jackson" instead of, say, the variable USER set to pejack.
    – Nordlöw
    Feb 2 '13 at 12:08
  • 1
    It's often nicer to see full names in commit logs.
    – Nordlöw
    Feb 2 '13 at 12:10

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 "user@example.tld"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.