M BUZZ CRAZE NEWS
// news

ps aux for long charactered usernames shows a plus sign

By Sarah Rodriguez

I'm trying to get an output from ps aux so that it looks like:

giovanni 28331 4381 0 15:43 ? 00:00:00 sshd: giovanni@pts/1
giovanni 28346 28331 0 15:43 pts/1 00:00:00 -bash
giovanni 28646 28346 0 15:43 pts/1 00:00:00 ./example.sh

However, running this command on Ubuntu 14.04 LTS, gives the following instead:

giovan+ 28331 4381 0 15:43 ? 00:00:00 sshd: giovanni@pts/1
giovan+ 28346 28331 0 15:43 pts/1 00:00:00 -bash
giovan+ 28646 28346 0 15:43 pts/1 00:00:00 ./example.sh

So how can I remove these plus signs and instruct the command to show me the whole username instead?

1

2 Answers

According to man ps, ps -aux is "To see every process on the system using standard (UNIX) syntax". I found no way to set a user-defined format to display the output.

In BSD syntax however, you can set the width of the column like: user:<width>. The following should give you the same information, setting the username column width to 20 (or any other value):

ps axo user:20,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm

output with (very) long name:

USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
.........................................................................................
root 3826 0.0 0.1 77828 4788 ? Ss 08:15:55 00:00:00 cupsd
lp 3831 0.0 0.0 63156 2224 ? S 08:15:56 00:00:00 dbus
lp 3832 0.0 0.0 63156 2220 ? S 08:15:56 00:00:00 dbus
root 4822 1.7 5.1 446964 210416 tty8 Ss+ 08:38:00 00:03:27 Xorg
root 4923 0.0 0.1 174652 4412 ? Sl 08:38:02 00:00:00 lightdm
tantemarievanhier 5181 0.0 0.1 544216 4796 ? Sl 08:38:08 00:00:00 gnome-keyring-d
tantemarievanhier 5228 0.0 0.0 40492 2740 ? Ss 08:38:08 00:00:00 init
tantemarievanhier 5369 0.0 0.0 41816 3064 ? Ss 08:38:09 00:00:02 dbus-daemon
tantemarievanhier 5376 0.0 0.0 10616 316 ? Ss 08:38:09 00:00:00 ssh-agent

setting column width to 7:

ps axo user:7,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
.........................................................................................
tantem+ 6623 0.0 0.0 287228 3820 ? Sl 08:39:00 00:00:00 unity-webapps-s
tantem+ 6679 0.0 0.4 676856 18640 ? Sl 08:39:20 00:00:00 update-notifier
tantem+ 6721 0.0 0.1 541224 7056 ? Sl 08:40:20 00:00:00 deja-dup-monito
tantem+ 6743 0.0 0.5 810616 21888 ? Sl 08:41:55 00:00:00 unity-scope-hom
tantem+ 6758 0.0 0.2 717256 10352 ? Sl 08:41:55 00:00:00 unity-files-dae
tantem+ 6760 0.0 0.5 607208 22920 ? Sl 08:41:55 00:00:00 unity-scope-loa
tantem+ 6784 0.0 0.2 350676 9060 ? Sl 08:41:56 00:00:00 unity-music-dae

For convenience reasons, you could add the following line to ~/.bashrc:

alias psaux='ps axo user:20,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm'

so that ps aux is the "normal" output, while psaux gives you the full name- version.

Note:

You can also show the full name by moving the name column to the last position:

ps axo pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm,user

gives:

 PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND USER 5181 0.0 0.1 544216 4548 ? Sl 08:38:08 00:00:00 gnome-keyring-d tantemarievanhier 5228 0.0 0.0 40492 2668 ? Ss 08:38:08 00:00:00 init tantemarievanhier 5369 0.0 0.0 41816 3032 ? Ss 08:38:09 00:00:07 dbus-daemon tantemarievanhier

How to display the output, setting the width of the USER column automatically

There is another, more refined way to set the width of the USER- column. If we run the command with a very high value for the USER column width, we can use a small script to rearrange the lines, adjusting the column width to the longest user name.

To do so

  • Copy the script below, paste it into an empty file, save it as psaux_alternative.py.
  • Make it executable
  • Add a line to your ~/.bashrc:

    alias psaux='/path/to/psaux_alternative.py`

Then, running psaux in a terminal window will display the output with an automatic width of the USER column.

The script:

#!/usr/bin/env python3
import subprocess
command = "ps axo user:30,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,comm"
l = subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8").split("\n")
minlen = sorted(set([30-len(item.split(" ")[0]) for item in l]))[0]
for line in l: print(line[:30-minlen]+line[30:])
7

I encountered the same problem. The ps manual tells us about WIDE-WCHAN-COLUMN. A smart try with parallel formed WIDE-RUSER-COLUMN ended in the wanted result:

$ ps -e -o ruser=WIDE-RUSER-COLUMN
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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