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.

What is the best way to find out if the current user is logged in via a local console on a Debian Linux machine (ttyS0 in my case)? I have a script where I want to restrict some options which would break a network connection. The who commands lists current users and their connections, but potentially the user could be logged in via multiple connections simultaneously and I don't known which one is me.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

If you want to get informations about the current connexion, you can use who -m, which will restrict whooutput to the current shell.

Or you can simply type who am i in a shell, it's an alias for who -m. ;-)

share|improve this answer
    
Nice! The description in the man page was too subtle for me! –  Bruce Alport Jul 25 '13 at 12:39
add comment

Well you can use the w command:

w command is used to show logged-in user names and what they are doing. The information will be read from /var/run/utmp file. The output of the w command contains the following columns:

Name of the user
User’s machine number or tty number
Remote machine address
User’s Login time
Idle time (not usable time)
Time used by all processes attached to the tty (JCPU time)
Time used by the current process (PCPU time)
Command currently getting executed by the users

Or if you just want to see who's logged in use who

For more info regarding the commands check the man page like this:

man w and man who

share|improve this answer
add comment

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.