Terminal 101: 3 Simple System Tricks
Posted 04/16/2012 at 11:09am
| by Cory Bohon

Every Monday, we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!
We’ve covered a lot of powerful Terminal commands over the past few weeks, but this Monday we’re going to focus on the smaller, softer side of Terminal commands. There are three different commands that allow you full control over your user account, including some options that may not be available in System Preferences. You can do things like directly authenticate your account from Terminal and check out who might be logged in your account. Read on to learn more.
sudo !! (bang bang)

Before you type in a long command into Terminal, add “sudo” to prevent your computer from blocking you out of the command. If you forget to do so, however, you might receive the “insufficient privileges” message, so type the following command:
sudo !!
When you press enter, the Terminal will copy the last command, and will prompt you for your administrator password. After authenticating, the command will continue with administrator privileges.
users / who
Want to see who’s logged into your system? Well you’re in luck, because there are two commands that can accomodate: users and who.

Typing users into the Terminal and pressing enter will show you the usernames of those users currently logged into your system.

You can also use the who command to do the same thing as the users command, but this comamnd will also give you more information about the user. Typing who will show you where the user is logged in (through Terminal, physical machine, SSH, etc.), and the date and time of login.
time
Want to know how long your Mac takes to execute a Terminal command. Well, that’s where the time command comes into play. Simply type the following command into the Terminal:
time <command here>
Replace the “<command here>” with any Terminal command. You’ll get a print out of the real, user, and system time that it took to complete the command.

Real time is referred to as “wall clock” time, which refers to how long a Terminal command took to execute. User time is the amount of time that the command spends in “user mode". System time is the amount of time that the program spends running in “kernel mode". You can calucate how long your processor takes to execute certain commands by adding the user time and the system time in Terminal. You'll discover that the CPU time is much slower than the real time, and that's because the CPU spends much of its time in a “wait state,” basically idling on standby until it's needed.
Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, Cory Bohon on Twitter.