Member Avatar for Member #545322

How to list out i"dle users only" using finger command? (Commandline)

$finger
Login      Name                  Tty      Idle  Login Time   Where
ravikumar  ravikumar            *:0      -         Sun 19:54 console
ravikumar  ravikumar            *pts/0    2:36     Sun 19:56 
ravikumar  ravikumar            *pts/1   -         Sun 22:08 
$ finger | tr -s " " | sort -k 4 
ravikumar ravikumar *pts/0 2:47 Sun 19:56 
Login Name Tty Idle Login Time Where
ravikumar ravikumar *:0 - Sun 19:54 console
ravikumar ravikumar *pts/1 - Sun 22:08

In the above usage how to get the number of idle users,
so that I can pipe with head command?

Opensuse uses '-' to represent idle state, suppose if Blank space is used
to indicate idle state Means, How to select the idle users, since "tr -s" is useless?

Dani AI

Generated

A practical, portable way to detect only idle sessions (useful for PuTTY/pts connections) is to use finger’s short output so the Idle column stays in a predictable position, then filter that column for tokens that actually represent elapsed time (numbers, colons, or the word old). This avoids fragile whitespace tricks like tr -s that break when the real-name field contains spaces. ’s suggestion to prefer who for remote-logins is reasonable; ’s who-based awk approach is a good alternative if finger is unavailable.

List idle sessions (any TTY) — short format, match typical idle tokens:

finger -s | awk 'NR>1 && ($4 ~ /[0-9]|:/ || $4 == "old") { print $1, $3, $4 }'

Only remote (PuTTY / pts) sessions:

finger -s | awk 'NR>1 && $3 ~ /^pts/ && ($4 ~ /[0-9]|:/ || $4 == "old") { print $1, $3, $4 }'

Count distinct idle users (useful for storing into a variable and piping to head):

idle_count=$(finger -s | awk 'NR>1 && ($4 ~ /[0-9]|:/ || $4 == "old") {print $1}' | sort -u | wc -l)

Then head -n "$idle_count" can be used against a previously produced list if a follow-up pipeline needs that value.

Caveats: different systems use - (often “no idle / not applicable”), . (usually <1 minute), old (long idle) or blanks — check finger -s output on the target host before scripting. If column positions still vary (long names, unexpected locales), parse with a small Perl/Python script that splits on columns by position or matches the idle pattern explicitly.

Recommended Answers

All 5 Replies

Bear in mind that console windows or tabs in the UI are represented by the *pts/0...n devices. In this case, ravikumar is logged in on the console and has two virtual terminals open, one of which has been idle for some time. I also keep a number of virtual terminals open on my system, each for different purposes, so in my case I have a couple with no idle time, and 2 with 5 day idle times. They don't take much memory or other resources, so it is usually best to leave them alone. Remote logins are another issue, and those are what you need to look for because they do take up network bandwidth just to keep the connection alive.

Member Avatar for Member #545322

Bear in mind that console windows or tabs in the UI are represented by the *pts/0...n devices. In this case, ravikumar is logged in on the console and has two virtual terminals open, one of which has been idle for some time. I also keep a number of virtual terminals open on my system, each for different purposes, so in my case I have a couple with no idle time, and 2 with 5 day idle times. They don't take much memory or other resources, so it is usually best to leave them alone. Remote logins are another issue, and those are what you need to look for because they do take up network bandwidth just to keep the connection alive.

Thanks for the Info. I just want to give an example. Actually I need to find out Idle users in our lab environment where we use PUTTY to connect to the server.

Thanks for the Info. I just want to give an example. Actually I need to find out Idle users in our lab environment where we use PUTTY to connect to the server.

That makes sense, and is the most common use for terminating idle connections. You also might want to check into the "who" command instead of finger. It will provide a lot of useful information, including old connections if you use the "-a" option. Anyway, read the man page.

who -Tu | awk '$7 !~ /\./ {print $1 , $8}' | sort -u

Member Avatar for Member #545322

who -Tu | awk '$7 !~ /\./ {print $1 , $8}' | sort -u

Thank you voidyman :cool:,

$who -Tu | tr -s " " | cut -d " " -f1,6 | grep "[^a-z?. ]"

How about this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.