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
Linux How to reset a root password on Fedora
Viewed 2806 times since Sun, Dec 6, 2020
How To: Linux Hard Disk Encryption With LUKS [ cryptsetup Command ]
Viewed 7561 times since Fri, Jul 13, 2018
Procedura powiekszania OCFS2 online
Viewed 5647 times since Fri, Jun 8, 2018
RHCS6: Clustered LVM
Viewed 2476 times since Sun, Jun 3, 2018
Tunnel SSH Connections Over SSL Using ‘Stunnel’ On Debian 7 / Ubuntu 13.10
Viewed 3556 times since Fri, Sep 28, 2018
HowTo: Retrieve Email from a POP3 Server using the Command Line
Viewed 11964 times since Mon, Feb 18, 2019
How to stop and disable auditd on RHEL 7
Viewed 40827 times since Tue, Aug 6, 2019
Configuring VLAN interfaces in Linux
Viewed 6010 times since Mon, May 21, 2018
logrotate How log rotation works with logrotate
Viewed 9259 times since Sun, Jan 12, 2020
7 Tips – Tuning Command Line History in Bash
Viewed 5755 times since Fri, Jul 5, 2019