25 Terminal Tips Every Mac User Should Know
Posted 12/11/2008 at 11:40am
| by Johnathon Williams

Terminal commands aren’t limited to the computer in front of you. One of their most practical applications is controlling other Macs through remote shell connections.
13. Establish A Secure Connection

SSH connections require less bandwidth and system resources than screen sharing.
SSH, or secure shell, opens a Terminal session on a remote machine, so all commands are then executed in the remote Terminal rather than the local one. The connection is encrypted, meaning none of the traffic passing between the two machines can be read if intercepted.
To get started, first make sure that SSH log-ins are enabled on the remote Mac by opening System Preferences and selecting the Sharing pane. Check the box next to Remote Login, and the SSH service will activate.
To connect to a remote computer via SSH, open the Terminal on the local machine and execute this command: ssh -l username remote-address.
Replace username with your username on the remote Mac and remote-address with the remote Mac’s IP address. (The remote IP address is listed in the remote machine’s Sharing pane when you click on Remote Login.) Press Return, and enter the remote username’s password at the prompt. SSH will connect you to the remote machine. (If you’re asked to add the remote machine to a list of known hosts, press Y for yes.)
Once you’re connected, you can execute any Terminal command remotely.
14. Freak Out Your Roommates

Your Mac’s reading voice won’t win an Oscar, but it’s plenty good for gags.
There are hundreds of useful remote commands, but let’s get you started with a good gag. If you know that someone else is using the remote computer, SSH into the machine, and execute say “Ouch. Don’t press the keys so hard.”
The remote machine’s default voice will read the statement over the speakers. This is even funnier if can do it from a laptop in the next room. (Please use this power responsibly. Impersonating deities or the Department of Homeland Security is bad form.)
Pranks aside, say can quickly create a machine-read audio book from a text file. Execute say -o savedaudio.aiff -f file-to-read.txt. Say will convert the file and save it as savedaudio.aiff in the Terminal’s current directory.
15. Troubleshoot A Remote Server’s Network Connection

Ping is a little like the Energizer Bunny: It keeps going and going. Press Command-Z to interrupt it.
Remote servers are great--until they stop responding. Then one of the first questions to answer is whether the entire machine has gone offline or whether a particular service (such as remote log-in) has stopped responding. To find out, execute ping remote-address. (For instance, to ping our home file server from work, we execute ping 72.204.20.186.) The utility will send a generic knock-knock to the server. If the server is still operating and attached to the network, ping will display each response, along with the time it took to receive it.
16. Copy Files Across A Secure Network connection

Be careful with syntax and argument order when using SCP. The longer the command, the easier it is to make a typo.
The next time you leave your jump drive at home, grab the files you need over the network with secure copy, or SCP, which piggybacks on SSH, so you’ll need Remote Login enabled on the remote machine. The syntax for this command can get a bit long--in addition to the remote machine’s address and log-in info, you’ll need the names and locations of the files you want to copy--but it’s well worth the effort if it saves your bacon for that big client presentation. Like SSH, SCP transfers data over an encrypted connection.
To copy a file from a remote machine, execute scp username@remote-address:path-to-file target-file.
For instance, to copy a file called rental_agreement.doc from our remote machine to a new file called agreement.doc on our local machine, we’d execute scp tandorra@10.0.1.5:/Users/tandorra/Desktop/rental_agreement.doc agreement.doc.
Obviously, the burden in this situation is knowing the exact location and name of the file before transferring it. Copying a file from your local machine to a remote one is a little easier. In that situation, we’d execute scp file-to-copy user@remote-address:path-to-new-saved-file.
In our example, we could also replace our originally copied file--agreement.doc--to the remote machine with this command: scp agreement.doc tandorra@10.0.1.5:/Users/tandorra/Desktop/agreement.doc.
17. Turn Off A Mac Remotely

Executing shutdown while someone else is in the middle of something important on the remote computer is mean, so use it with caution, OK?
If you need to turn off a Mac after leaving the house, SSH into the machine, and execute sudo -h shutdown now.
Next Manage and Adjust Text