This is the first in a series of planned tutorials for anyone who wants to find out what Terminal can do and how they can use it to increase the usability of their computer. Unlike other Terminal tutorials, I’m going to assume that you’re not interested in giving up the desktop for the command line to do things like move and copy files that you can do more easily in Finder. Rather, I’m only going to focus on those things that it’s generally more difficult (or impossible!) to do in the GUI than it is in Terminal.
Let’s get started. Open Spotlight (try the hotkey command + spacebar or click the spy glass in the top right corner) , then type term and press Return.
When Terminal opens, the first thing you may want to do is make the text a bit easier to see in the Terminal window.
Hold down command-shift-+ to increase the size. Try it a couple of times till the text is a comfortable size. If you overshoot, just use command- – (minus key) to reduce text size.
Now you’re sitting comfortably in your Terminal window, let’s learn our first spell. Actually, we’re not going to learn one so much as make our own!
In order to do that, we want to open a hidden file and edit it. In Terminal, type
(There’s a space after ’emacs’, and, don’t forget that . dot right before the ‘b’)
What you see after this screen may vary depending on whether .bash_profile has any pre-existing content or not. If there is anything in the file already, ignore it and use the arrow key to move the cursor to a clean line at the bottom. If the file is empty, then just start typing. The first line we want to type is
Now press Return and enter a single, left curly bracket
Press Return again and type (or copy and paste) this:
There’s a space between the ‘s’ and the dash, and all the letters are lowercase except the ‘F’, which must be uppercase.
Press Return and provide the closing curly bracket
It should look like the area inside the orange rectangle:
Now hold down the control key on your keyboard while you first press x and then c. Notice at the bottom of the screen you get a ‘save’ warning.
Press the y key on your keyboard, and you should find yourself returned back to the Terminal prompt.
Type exit at the prompt to logout of the Terminal, and then on the keyboard press Command-W to close the window, and Command-N to open a new Terminal session.
What did we just do?
We defined and saved a new Terminal command called show which we can now use whenever we enter Terminal to easily see all the files and folders – including all the hidden ones – in any given directory. To see what we just did, type show at the command line. You should get an output that is formatted something like this:
As you can see I’ve annotated the screenshot to show some of the features that the show command gives us. First of all, notice the file and folder names that begin with a . dot. These are your hidden files and folders (Remember: they are usually hidden for a reason, so don’t go messing with them unless you know what you’re doing!). The show command also helps us distinguish between files and folders by appending a / slash to the end of folder names. Although not shown here, you may also see some names with an * at the end. That means it’s an executable file — in other words, its purpose is to run some programme or command.
The show command is very useful for seeing exactly what is in a folder, but of course we need to know how to move between folders in order to see anything other than our own home directory.
Suppose I want to have a look in that folder called ‘Shared’. Then what I do is I type
then press the tab key on the keyboard. The rest of the name is filled in for me by Terminal:
The tab key is a very useful trick for moving around in Terminal when you are faced with long names. Generally, you only have to type in enough to make the file or folder name unique and hitting tab will complete the rest of the name for you. However, if I only type
and then press tab, nothing happens. Terminal can’t complete the name because there’s more than one choice. However, if I press tab again, Terminal will give me a list of the all names that begin with S:
pressing tab twice gives:
Now I can see all the options, and how much I have to type to make a unique choice. In this case, I only have to type either ‘cd Sh’ or ‘cd Sn’ to allow Terminal to know which one I want when I press the tab key. Pressing Return after the tab completion will take me to the folder.
Try it with a folder from your own list.
After changing to a new folder, perhaps your screen is getting a bit messy. Let’s clean it up before doing show again. On the keyboard, press control-L to get a clear screen (notice that all your previous commands and outputs are still available if you scroll up!).
Now type show again to see your files and folders, pick a folder (if there is one), and type cd plus the first few letters of the name. Fill it out with the tab key and then press Return.
Again, type show to find out what’s inside. You can keep going deeper into the directory tree by using cd and show on any folders you find.
The last thing we need to know for today is how to go back up the tree, or to move back to the parent folder. Again we’re going to use the ‘cd’ command, but this time you don’t need to type any names. Just a space and then two dots
(don’t forget there’s a space between the ‘d’ and the two dots). This will always take you to the parent folder of the folder you’re currently in, all the way up to your hard disk’s parent directory. If you want, you can make a new up command (just like we made show) as a shortcut for ‘cd ..’. Have a look at the smallest of the screenshots above and see if you can do it. 🙂
So now you know how to move around and see all the hidden and un-hidden contents of your drive, go and explore and get yourself used to these first basic commands.
When you’ve finished with your Terminal session, type exit and press Return. You can then close the window and go back to GUI land!
. at the beginning of a name means ‘hidden’
/ at the end of a name means ‘Folder’
* at the end of a name means ‘executable file’
cd – move in to that folder
cd .. – move back to the parent folder
emacs – opens the Terminal textfile editor
show – shows a complete list of a directory, including hidden files
control-L – clears the Terminal screen
tab – will try to complete file or folder names
tab (twice) – will offer choices
learning the Terminal – Part Two
If you have Parallels or VMFusion, you can download and run Ubuntu as a guest OS for free. Ubuntu has some nice features including a Spaces-like desktop switcher and loads of free software available in the Ubuntu App Store.
For those still on Snow Leopard but wishing they could have the benefits of iCloud, Ubuntu provides an interesting option: the open source OS comes with its own Cloud service and 5GB free space. You can sync it with Windows, Android and iOS, and it even allows you to stream music from the Cloud to your devices. If you run Ubuntu in Parallel’s ‘Coherence’ mode, you can take advantage of Ubuntu’s mail, calendar and music apps and have all your other devices synced to your Mac.
If you want to read more, go to the Ubuntu website. When you’re ready to give it a spin, it couldn’t be simpler:
1. Go to the Ubuntu download page, and choose either 32-bit or 64-bit depending on your current Mac OS (if you’re running SL 10.6.8 or later, go for the 64-bit). Ignore the advice about creating a CD or USB stick (it doesn’t apply to us as we’re going to install it via Parallels).
2. Click the big red/orange ‘Download’ box, and make a cup of tea while the .iso file downloads to your computer.
3. After the download has finished, start up Parallels. From the Parallels Desktop menubar, choose File > New.
4. From the resulting dialogue box, click the drop down menu and select Choose an image file…. Browse to your downloads folder and choose the .iso file you downloaded in step 1.
5. From here on in, Parallels will pretty much take care of everything else for you. Your virtual machine will restart a couple of times and you will get asked to choose a couple of options (like setting a language, region and password), but it’s all fairly self-explanatory. Accept the default options for now.
When the install finishes, the first thing to do before trying it out is to set the amount of RAM available to the Ubuntu install. You’d want to set this to at least 2GB, but 4GB is better to get a really fast machine.
6. To set the RAM, first shut down Ubuntu. Do so by going to the Parallels menubar and choosing Virtual Machine > Shutdown.
7. After the OS has shutdown, go back to the Parallels menubar and choose Virtual Machine > Configure. Click on General and set the slider to as much RAM as you can spare…
8. Finally, go play! Depending on your download speed, the whole procedure shouldn’t take much more than an hour or so. If you need documentation, just go back to the Ubuntu site and you’ll find plenty of resources there.