Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a command in linux to display the amount of time a user has logged in? The 'who' command displays only the users connected.. how about the time a user is logged in?

share|improve this question
    
Is there a difference? –  Daniel Beck Aug 25 '13 at 13:36

2 Answers 2

If you run who -H you can see the column names:

x-cash@runabout:~$ who -H
NAME     LINE         TIME             COMMENT
x-cash   tty7         2013-08-20 10:23 (:0)
x-cash   pts/0        2013-08-25 15:45 (:0)

As you can see, the column TIME is exactly what you're looking for. Just subtract that value from the actual time.

share|improve this answer
    
thank you...... –  subhashini Aug 25 '13 at 14:04
    
@subhashini you're welcome. Remember to accept the answer. –  Paolo Casciello Aug 25 '13 at 14:14

You can parse the output of who or w to get the time a user logged in. If you then parse the dates and compare them to "now", you can get how long a user has been logged in. For example, to get the time in minutes:

who | awk '{print $1,$3,$4}' | while read user time; do \
  echo $user $(($(($(date +%s) - $(date -d "$time" +%s)))/60)) minutes; done 

terdon 39 minutes
terdon 31 minutes
terdon 23 minutes
terdon 22 minutes
terdon 20 minutes
terdon 18 minutes
terdon 15 minutes
guest 15 minutes
terdon 13 minutes
terdon 12 minutes
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.