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
ZFS: Remove an existing zfs filesystem
Viewed 1874 times since Sun, Jun 3, 2018
stunnel Securing telnet connections with stunnel
Viewed 1237 times since Sun, Dec 6, 2020
Linux Health Check Commands
Viewed 2739 times since Fri, Jun 8, 2018
Linux – Securing your important files with XFS extendend attributes
Viewed 7308 times since Wed, Jul 25, 2018
How to enable automatic security updates on CentOS 7 with yum-cron
Viewed 2232 times since Fri, Oct 26, 2018
How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD find
Viewed 3389 times since Mon, Oct 29, 2018
8 Vim Tips And Tricks That Will Make You A Pro User
Viewed 2698 times since Fri, Apr 19, 2019
systemctl Use systemd to Start a Linux Service at Boot
Viewed 5177 times since Mon, Dec 7, 2020
Linux 20 Netstat Commands for Linux Network Management
Viewed 9180 times since Mon, Sep 21, 2020
10 Linux cryptsetup Examples for LUKS Key Management (How to Add, Remove, Change, Reset LUKS encryption Key)
Viewed 4818 times since Tue, Jul 31, 2018