Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
1  
What platform are you on? Use uname -a –  Kevdog777 Dec 13 '13 at 9:23
1  
@Kevdog777 I updated the question, and added uname -a –  guettli Dec 13 '13 at 11:36

3 Answers 3

Looking at the sources of top, it seams 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 pritnf format string. %-8.8s means left padded string of minimum and maximum size of 8.

share|improve this answer

It looks like there is currently no way to do this as you request with terminal programs. What you ask is not new and actually is on htop feature request list, but it has been that way for a year and a half and no milestone has been set to implement this yet. No sign of that at all for top. 2 options could be:

1) Two terminals

You can tell top (e.g. you can use f as it runs) to show the UID not the name. If you have split your terminal in 2 fields such as with terminator or screen then you can run top in the upper larger screen and query for the username in the lower e.g.

awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd

substituting whatever UID you want to look at for 1000. Of course, you could wrap it in a very small bash script so you should only type a few letters of your script name and the UID. Also if you are talking about non local users you can use getent passwd as input for awk instead of /etc/passwd file - like so:

getent passwd | awk -v val=1000 -F ":" '$3==val{print $1}'

2) ps option

You could use ps to give you 15 most CPU heavy processes and who they belong to. You can vary the number of processes of course.

ps -ef | egrep -v "STIME|$LOGNAME" | sort -k4 -r | head -n 15 | colrm 100

Explanation:

ps -ef                     gives you all processes 
egrep -v "STIME|$LOGNAME"  removes the header line
sort -k4 -r                sorts by the CPU column in reverse (biggest on top)
head -n 15                 gives you first 15 lines of above
colrm 100                  restricts each line of output to 100 characters 

The last command is useful as some programs sch as google chrome have very long options lines after the command, so your output will be difficult to read if you don't cut the lines.

share|improve this answer

Not really the answer but you could use htop instead

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Karlson Dec 13 '13 at 18:15

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.