How can I increase the ps column width for column "user"?

If you know that a long command with multiple options does what you want, but you don't want to type it each time, then (assuming you're using Bash) you can create an alias for that command to make it easier. For example:

alias ps_mod='ps ax o user:16,pid,pcpu,pmem,vsz,rss,stat,start_time,time,cmd'

Then you can just type that simple command. You can add this line to your ~/.bash_profile (or ~/.bashrc, depending on your system) file, so that it is defined automatically on login.

If you're not using Bash, then you can probably do something similar by defining a shell function instead.


Tiny patch to procps-ng source

Seems a quick patch of the source code would do the trick; normally the user column is set to 8 and will truncate as detailed below.

Patch applies to commit 64fa8898 which was tagged v3.3.5 (linked above)

You might as well download the latest source if you're going to compile it though—I'd suggest downloading the latest source and edit the "USER" line in procps-ng source file ps/output.c from 8 to 16 as below instead of patching the old (2013-ish) version:

---
 ps/output.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ps/output.c b/ps/output.c
index 9644ed3..41c2eda 100644
--- a/ps/output.c
+++ b/ps/output.c
@@ -1564,7 +1564,7 @@ static const format_struct format_array[] = {
 {"uname",     "USER",    pr_euser,    sr_euser,   8, USR,    DEC, ET|USER}, /* man page misspelling of user? */
 {"upr",       "UPR",     pr_nop,      sr_nop,     3,   0,    BSD, TO|RIGHT}, /*usrpri*/
 {"uprocp",    "UPROCP",  pr_nop,      sr_nop,     8,   0,    BSD, AN|RIGHT},
-{"user",      "USER",    pr_euser,    sr_euser,   8, USR,    U98, ET|USER}, /* BSD n forces this to UID */
+{"user",      "USER",    pr_euser,    sr_euser,  16, USR,    U98, ET|USER}, /* BSD n forces this to UID */
 {"usertime",  "USER",    pr_nop,      sr_nop,     4,   0,    DEC, ET|RIGHT},
 {"usrpri",    "UPR",     pr_nop,      sr_nop,     3,   0,    DEC, TO|RIGHT}, /*upr*/
 {"util",      "C",       pr_c,        sr_pcpu,    2,   0,    SGI, ET|RIGHT}, // not sure about "C"
-- 

Addendum

According to the source for the ps:

// The Open Group Base Specifications Issue 6 (IEEE Std 1003.1, 2004 Edition)
// requires that user and group names print as decimal numbers if there is
// not enough room in the column.  However, we will now truncate such names
// and provide a visual hint of such truncation.  Hopefully, this will reduce
// the volume of bug reports regarding that former 'feature'.
//
// The UNIX and POSIX way to change column width is to rename it:
//      ps -o pid,user=CumbersomeUserNames -o comm
// The easy way is to directly specify the desired width:
//      ps -o pid,user:19,comm
//

Tags:

Shell

Ps