List usernames instead of uids with the ps command for long usernames

Have your ever faced such a situation. You have usernames in your /etc/passwd file with more than 8 characters. This is no problem for Linux at all, usernames may be up to 32 characters long, only your ps output might look a little scrambled.

It shows you the uid instead of the username like in the following example:

1
2
3
4
5
6
7
8
9
$ id
 
uid=20001(longuser01) gid=10002(oinstall) groups=10002(oinstall)
 
$ sleep 1000000 &
 
$ ps -ef | grep sleep | grep -v grep
 
20001    14069 11739  0 14:11 pts/0    00:00:00 sleep 1000000

 

But you want to see the username instead of the uid. The workaround is

  • Don’t use more than eight characters for your usernames  :-)
  • Or …. format your ps output the right way

You could use the following alias to get the job done.

1
2
3
4
5
$ alias psx='export PS_FORMAT="user:12,pid,%cpu,%mem,vsz,rss,tty,stat,start,time,command"; ps ax'
 
$ psx | grep sleep | grep -v grep
 
longuser01 14069  0.0  58940 520 pts/0 S 14:11:50 sleep 1000000

 

Now it looks better.

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
How to use yum-cron to automatically update RHEL/CentOS Linux 6.x / 7.x
Viewed 5006 times since Tue, Dec 4, 2018
Open SSL Encrypt & Decrypt Files With Password Using OpenSSL
Viewed 8156 times since Mon, Feb 18, 2019
RHEL: GPT/MBR partition tables (using disks larger than 2 TiB)
Viewed 12289 times since Sun, May 27, 2018
Linux nslookup Command Examples for DNS Lookup
Viewed 8963 times since Sat, Sep 29, 2018
SSH Essentials: Working with SSH Servers, Clients, and Keys
Viewed 4436 times since Wed, Jun 27, 2018
RHCS: Install a two-node basic cluster
Viewed 9974 times since Sun, Jun 3, 2018
Using stunnel and TinyProxy to obfuscate HTTP traffic
Viewed 6870 times since Fri, Sep 28, 2018
ZFS: Snapshots and clones on zfs filesystems
Viewed 3084 times since Sun, Jun 3, 2018
RHEL : How to deal with “CLOSE_WAIT” and “TIME_WAIT” connection
Viewed 25827 times since Thu, Feb 14, 2019
Netcat shell zabezpieczony hasłem
Viewed 2223 times since Thu, May 24, 2018