Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
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
    
It's often nicer to see full names in commit logs. –  Nordlöw Feb 2 '13 at 12:10

1 Answer 1

up vote 4 down vote accepted

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"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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