stack
stack

Reputation: 841

how to display the entire username while the username is too long in linux

In my project, I want to select the username or userid in processes in my linux server

I used the command like:

ps aux | grep -v root

I got some content like this:

mae-wan+  34325 99.7  0.5 1717096 1056124 ?     Rl   Apr18 1533:33 ./turb
mae-wan+  34326 99.7  0.5 1717128 1057284 ?     Rl   Apr18 1533:35 ./turb
mae-wan+  34327 99.7  0.5 1716992 1056860 ?     Rl   Apr18 1533:41 ./turb
mae-wan+  34328 99.7  0.5 1717244 1056644 ?     Rl   Apr18 1533:43 ./turb
mae-wan+  34329 99.7  0.5 1717100 1054616 ?     Rl   Apr18 1533:43 ./turb
mae-wan+  34330 99.5  0.5 1717100 1057640 ?     Rl   Apr18 1530:33 ./turb

The first column is:

mae-wan+

So the entire name should be:

mae-wangjc

Perhaps, the name mae-wangjc is too long, and it display to mae-wan+

As a result, I had to use:

ll /proc/34325 | awk '{print $3}' | uniq

I can get the name "mae-wangjc" successfully. but i think it is ugly for solving each process one by one.

which command can display the entire user name instead of abbreviating names?

Upvotes: 3

Views: 7765

Answers (2)

Shawn
Shawn

Reputation: 52529

Try this:

$  ps aunx | perl -lane 'BEGIN{$, = "\t"} print getpwuid $F[0] // $F[0], @F[1..$#F]'

The n option prints out uids instead of user names, and then the perl bit looks up the usernames of the uids (Or keeps using the uid if there is no associated name) and prints out the lines with tab-separated columns.

Upvotes: 1

Ahmed
Ahmed

Reputation: 345

According to man ps, ps -aux is "To see every process on the system using BSD syntax".

In standard syntax however, you can set the width of the column like: user:. 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

the result will be like that:

mae-wangjc  34325 99.7  0.5 1717096 1056124 ?     Rl   Apr18 1533:33 ./turb
mae-wangjc  34326 99.7  0.5 1717128 1057284 ?     Rl   Apr18 1533:35 ./turb
mae-wangjc  34327 99.7  0.5 1716992 1056860 ?     Rl   Apr18 1533:41 ./turb
mae-wangjc  34328 99.7  0.5 1717244 1056644 ?     Rl   Apr18 1533:43 ./turb
mae-wangjc  34329 99.7  0.5 1717100 1054616 ?     Rl   Apr18 1533:43 ./turb

Upvotes: 5

Related Questions