6

Is it possible to check for how long a user has been logged in? Or when the user logged in on an Unix/Linux system?

I logged in as another user on my system a while ago and I would like to now how long that user has been logged in.

2 Answers 2

9

Using last you can find this information. The following may be useful:

last <username> | less

It will return something like this:

benlavery@Talantinc:bin $>last benlavery | less
benlavery  ttys005                   Mon Aug 31 09:58   still logged in
benlavery  ttys005  fe80::105e:6b27:29ff:d967%en0 Mon Aug 31 09:14 - 09:36  (00:22)
benlavery  ttys005  fe80::105e:6b27:29ff:d967%en0 Mon Aug 31 09:12 - 09:14  (00:01)

You can see when the user logged in and when they logged out—or if they are still logged in.

1
  • 4
    You can also use the w command.
    – jofel
    Commented Aug 31, 2015 at 9:54
1

To find how much time you have been logged in, run this command from the original login shell:

ps -o etime= -p $$
1
  • To see your parent shells, use ps ao etime. This does not answer for any user, however.
    – fde-capu
    Commented Jun 23, 2022 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .