Full user name linux

Full username in top

On our systems user names can be up to 20 characters long. But the top commands only displays the first 8 characters. How can I configure top to display the whole user name? At the moment we use: top procps version 3.2.8 (linux) But a different top implementation could be installed. The oldest system we need to support is this:

Linux foohost 2.6.37.1-1.2-desktop #1 SMP PREEMPT 2011-02-21 10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux 

4 Answers 4

Looking at the sources of top , it seems that there’s a hardcoded maximum of 8 chars:

1223 static FLD_t Fieldstab[] = < 1229 keys head fmts width scale sort desc lflg 1230 ------ ----------- ------- ------ ----- ----- ---------------------- -------- */ 1235 < "EeDd", " USER ", " %-8.8s", -1, -1, SF(URE), "User Name", L_EUSER >, 

The fmts colum is a printf format string. %-8.8s means left padded string of minimum and maximum size of 8.

Can’t really help you with older 3.2.x versions of procps but in newer ones (e.g. definitely 3.3.10 and I think it went back to 3.3.4) you can adjust the size of fixed columns. The key you are looking for is capital X.

To use this feature, first start top. Ideally, but not essential, you will «make room» for your column by either removing other columns or expanding your terminal. Use f to bring up your field list and deselect what you don’t need. Once you are happy with field selection, hit q to get back to the process list.

Then use X command which asks you for how much to increase the width, generally -1 works ok. You might get this strange «column growing» effect but after a few refeshes you can see the full username.

 PID USER PR VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3775 libvirt-qemu 20 4667404 960508 14724 S 6.1 5.9 188:04.01 qemu-syste+ 3825 Debian-gdm 20 1516152 114924 64404 S 2.7 0.7 1:52.09 gnome-shell 

Notice that the command name is now truncated (ends with a +) because our username is longer and has pushed the other columns to the right. Whether or not you think this a a good idea depends what you are looking for.

Читайте также:  Поменять владельца директории linux

Источник

How To Change User Full Name In Linux?

How To Change User Full Name In Linux?

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.

Show User Full Name

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.

Change User Full Name with chfn Command

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

Change User Full Name with usermod Command

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

Change User Full Name via /etc/passwd File

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.

Change User Full Name via GUI (Gnome)

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.

Читайте также:  Resetting windows password with linux

Just edit the user’s full name and click different locations to save the new full name.

Источник

What’s the easiest way to get a user’s full name on a Linux/POSIX system?

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.

10 Answers 10

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.

Источник

How to get the logged in user’s real name in Unix?

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:» ‘‘ These will work fine if there are multiple users. It just pulls the one specified.

Читайте также:  Linux check open ports remote

7 Answers 7

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." 

Источник

How can I find out my user name ( system login username in ubuntu 20.04 )? [closed]

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.

enter image description here

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).

1 Answer 1

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.

Example; name= John Doe, automatically set username= john

Источник

Оцените статью
Adblock
detector