Skip to content
Advertisement

Unable to print usernames longer than 8 chars with “w” in linux

I am doing a linux script to extract which users are logged onto a machine, from where, and how long they have been idle. So far I have been using the “w” command in linux. However I now noticed that it truncates usernames and source

I have three users logged on testuser testuser-new lala-testuser

They are logged on from either: testserver, or superdupertestserver

The output of w is:

testuser   pts/2    testserver       10:12   29.00s  0.15s  0.15s -bash
testuser   pts/3    superdupertestse 10:12   21.00s  0.18s  0.18s -bash
lala-tes   pts/4    superdupertestse 10:12   21.00s  0.18s  0.18s -bash

I am already using “long listing” of the output. Is there a way to fix this, or do get the information from the source w is using?

Advertisement

Answer

man w:

ENVIRONMENT
       PROCPS_USERLEN
              Override  the default width of the username column.  Defaults to
              8.

       PROCPS_FROMLEN
              Override the default width of the from column.  Defaults to 16.
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement