Skip to main content

hi guys

Was wondering if you can help me.

For my scripts i usually use below for the currently logged in user

ls -l /dev/console | cut -d " " -f4

this returns tkimpton@rufusleonard.hq

Im trying to work out how to strip out @rufusleonard.hq so i am left with tkimpton.

Any ideas?

Do you get a better result with the following?-

/usr/bin/who | awk '/console/{ print $1 }'

If not, you can use your command and send it through another cut like this-

| cut -d@ -f1

That should leave you with everything from before the @ symbol, meaning "tkimpton'


OMG wow that if friggin awesome.

Thank you very much

went on a bender last night and my brain has b een hitting a brick wall ;)


following in the "1001 ways to do" X tradition: ```
who | grep console | awk '{print $1}'
```


/dev/console does seem to be a bit more reliable, sometimes when logging out one user and logging in a new one who on the console can produce less than consistent results in my experience anyway...


Yet another way which avoids grep and awk:

stat -f "%Su" /dev/console


Thanks guys :)


You can also read the lastUser key from com.apple.loginwindow.plist