Quantcast

Special Sponsored Section


The video player requires Flash 8 Player or later. Please download the latest Flash Player.


Maclife Hottest Articles
Thumbnail
FEATURE
100 Snow Leopard Tips, Tricks, and Features
Browser
FEATURE
OS X Browser Speed Wars: May the Fastest App Win
iTunes History
FEATURE
The Complete iTunes History -- SoundJam MP to iTunes 9
iTunes Tips
FEATURE
iTunes 9 Tips and Tricks - Solve the Mysteries of the New iTunes

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

 

remote

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


Screen shot of local network
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


screen shot of quick time players
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

screen shot line code commands
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


screen shot of line code
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


Screen shot of line code
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

COMMENTS
avatarGreat article

And lest some users are thinking this is too uber-geeky for mere mortals such as themselves, it's worth mentioning that highlighted text from any text document can be dragged right into an open terminal window. If anyone were uncomfortable typing directly in Terminal, they could save a document of their favorite commands and just drag 'em over. Easy.

Login or register to post comments
avatarA very timely article!

What a very timely article (for me at least!). I was just looking into this... It is always a hassle setting up a new computer, it would be nice if I could just run a script that would configure some/most of my system for me. I've found some commands that looked promising but ran into a few road blocks... I went to my local Apple Store and there the Genius told me that they didn't do Unix! That sucks. Here what I have so far:I randefaults read com.apple.finder DesktopViewOptions{ IconViewOptions = { ArrangeBy = none; BackgroundFlags = 0; BackgroundType = DefB; FontSize = 12; GridSpacing = 73; IconSize = 48; PropertiesLocation = botm; ShowPreviewIcon = 1; ViewMoreInfo = 0; };}I could reset the icon size or the font size or the grid spacing but not all three of them at once by using one of the following:defaults write com.apple.finder DesktopViewOptions -dict IconSize -integer 32;defaults write com.apple.finder DesktopViewOptions -dict FontSize -integer 11;defaults write com.apple.finder DesktopViewOptions -dict GridSpacing -integer 40;killall FinderI'd like to do something along the lines of:defaults write com.apple.finder DesktopViewOptions { IconViewOptions = { FontSize = 11; GridSpacing = 40; IconSize = 32; };}But this does not work. Any ideas?

Login or register to post comments
avatarA very timely article!!

What a very timely article (for me at least!). I was just looking into this... It is always a hassle setting up a new computer, it would be nice if I could just run a script that would configure some/most of my system for me. I've found some commands that looked promising but ran into a few road blocks... I went to my local Apple Store and there the Genius told me that they didn't do Unix! That sucks. Here what I have so far:I randefaults read com.apple.finder DesktopViewOptions{ IconViewOptions = { ArrangeBy = none; BackgroundFlags = 0; BackgroundType = DefB; FontSize = 12; GridSpacing = 73; IconSize = 48; PropertiesLocation = botm; ShowPreviewIcon = 1; ViewMoreInfo = 0; };}I could reset the icon size or the font size or the grid spacing but not all three of them at once by using one of the following:defaults write com.apple.finder DesktopViewOptions -dict IconSize -integer 32;defaults write com.apple.finder DesktopViewOptions -dict FontSize -integer 11;defaults write com.apple.finder DesktopViewOptions -dict GridSpacing -integer 40;killall FinderI'd like to do something along the lines of:defaults write com.apple.finder DesktopViewOptions { IconViewOptions = { FontSize = 11; GridSpacing = 40; IconSize = 32; };}But this does not work. Any ideas?

Login or register to post comments
avatarFormat for comment suck...

How do you turn off the reformatting?

Login or register to post comments
avatarIf you're using TextEdit...

then click Format > Make Plain Text or press Shift-Command-T.  This will strip the document of all formatting (e.g. font, color, italicize, etc.).

Login or register to post comments
avatarVi(m) customization

i'd love to see some 411 on customizing Vi(m) on the mac. for when i want to edit a file without opening a bloated text editor (dreamweaver).

b

Login or register to post comments
avatarSome good info, but...

I'm relieved to see you corrected the "key" on the image in tip #3 as printed in this issue of the magazine, which was grossly incorrect. Now just change #15 to use Ctrl-C to stop ping, instead of Ctrl-Z (not Command-Z) which just suspends a command instead of stopping it. Yes, the picture says "Stopped", but it's still running. Type "fg" after hitting Ctrl-Z and you'll be taken right back to the ping. Same Ctrl-Z foolishness on #17.

Login or register to post comments
avatarVery good tips to follow. I

Very good tips to follow. I am sure that a lot of people didn't know about these things when it comes to using Mac. I am grateful that you thought about us and put this information in this post for us.

______

Royal Caribbean Cruises

Login or register to post comments
avatarCtrl-Z

Hi,Just a quick note about Ctrl-Z. When you use Ctrl-Z to stop a job or process that is running, it doesn't "kill" that process, just interrupts it and makes it wait. This is actually quite handy at times, because you have some job control you can do afterward:1) run the "jobs" command to see a list of jobs you've got waiting.2) run the "fg %#" command to bring a command back to active from the jobs list (use the number instead of the pound symbol).3) run the "bg %#" command to let a job run in the background (great for calculations and tasks that don't have much output!).4) run the "kill %#" command to kill the job.Be sure to put the percent symbol before the jobs list number, especially with the kill command, otherwise, it will use the process id (run "ps auxw" to see a list of all processes).Cheers,Andrew

Login or register to post comments
avatarSSH How do you find IP addresses of networked Macs using termina

I enjoy these types of articles. Keep them coming.

Re: SSH
So now that I'm ready to ssh into another Mac (or pc) on my home network, how do I discover their IP addresses without getting up out of my chair? I know that I can walk around the house and look in the Network Prefs to learn the IP address but I want to do it remotely. In my old Linksys router there was a panel in the web admin control screen showing the IP addresses of all the clients on my network. I don't see this in the Airport Utility for my new Time Capsule.

Is there a way to use the terminal to do this?

Matt

Login or register to post comments
avatarFining IP addresses

You can use a little app called Flame that will list all the IP addresses in your network.

Login or register to post comments
avatarQuestion about Secure Erase of Free Space on my HD

I executed this command "diskutil secureErase freespace 3 /Volumes/Macintosh\ HD" and it's running the erase but it seems to have doubled the contents of the HD, if only temporarily. Is this normal cause there's like Zero room left on my HD? Will it go away after the erase is complete? I just backed up w/ time machine on an external so I'm not super worried, but I'd just like to know what's going on.

Thanks
Nick

Login or register to post comments
avatarFollow up?

How did this work out for you?  Space back to normal?

Login or register to post comments
avatarA few more tips!

This list is great, and it goes from beginning to much more advanced.

Try

sudo !!
This reexecutes the last command entered as root. Great for when you get pesky 'Permission Denied' errors

A mac exclusive! When you have a file in the finder that you want to do something with, you can just drag it into terminal and it will put the path (the file's location) to that file where your cursor is.

Having trouble deleting a large amount of stuff from trash or taking too long to do the 'preparing to delete' thing? Try:

sudo rm -rf /.Trashes/*
or
sudo rm -rf /Volumes/Secondary-hard-drive/.Trashes/*

If you forget to put the .Trashes in the command, you could end up deleting a significant amount of important stuff.

Login or register to post comments
avatarGood tips..

Guys always remember to quit an application before modifying its defaults.
herpes - lasik surgery

Login or register to post comments
avatarThose are some very good

Those are some very good tips that everyone should pay attention to.
Air Mattress Bed
Air Mattress Bed Frame
camping air mattress
air mattress beds

Login or register to post comments
avatarPermission Errors?

I am the only one using my MacBook Pro. I would like to know where Permission errors come from.

Login or register to post comments
avatarI am sure that a lot of

I am sure that a lot of people didn't know about these things when it comes to using Mac. I am grateful that you thought about us and put this information in this post for us.knee pain | pain relief

Login or register to post comments
avataromega watches

Every little chat Salon 1000 ah!replica watchYou are my best's buddy
35rfd

Login or register to post comments
avataromega watches

Were not smart, but also learn from others bald.omega watchesChing had no water to fish, one to the cheap is invincible.replica watchI left Dragon, White Tiger right shoulder tattooed Mickey Mouse.replica watchesEfforts should be made! ! For your Audi Dior me.nong

Login or register to post comments
avatarthank you ar..is

thank you ar..is niceR$#
شات صوتي, دردشه صوتيه, شات مصريه, شات دردشة دردشه دردشة موبايل شات دردشه

Login or register to post comments