Programming for Non-Technical Founders – Part 2A: Terminal

The first tool in our arsenal is Terminal. Terminal is a terminal emulator. You may also hear it called a CLI (short for command-line interface), or a shell – these all refer to roughly the same thing.

You know how in the movies, whenever there’s a hacking scene, the resident hacker is banging away on the keyboard while a stream of text rapidly scrolls by? That’s a terminal emulator.

On your Mac,  you’ll find Terminal under Applications -> Utilities. Launch it now. You’ll be using it often, so you may want to add it to your dock.

You should be looking at a window with some text and a cursor. That’s Terminal. It’s purely text-based – there’s nothing graphical in Terminal. The way it works is you type a command, press Enter, and Terminal will print the output to the screen. That’s the whole interface. No buttons, menus or anything GUI.

Try typing the command

ls

and press Enter. (Note: that’s an L, not a 1) You should see a list of names that are strangely familiar. They should be: they’re the files and folders in your Home folder. Don’t believe me? Check for yourself. Open Finder and click on your Home folder under Places (it’s the one with the house). Compare the list in Terminal against what you see there and you’ll see they’re identical.

ls is short for “list”. The command lists the contents of your current folder. When you first open Terminal, your current folder is always your home folder.

Ok, so how do we change our current folder? In Finder, we’d just double-click on the folder we want to open, and that folder becomes our current folder. But that won’t work in Terminal. Click and double-click are graphical interface concepts, and in Terminal all we have is text commands.

The command to change your current folder is cd. cd is short for “change directory”, and directory is simply another word for folder (the terms are completely interchangeable). Let’s change to our Desktop directory. In Terminal, type

cd Desktop

Notice how when you press Enter, the prompt changes to let you know you’re in a new folder. List the contents and compare them the Desktop folder in Finder. Cool, huh?

Ok, let’s create a folder for our new project. We’re going to create it within the Desktop folder so we’ll have easy access to it. Since we’re already in the Desktop directory, just type and run the following commands in sequence:

mkdir dntutorial
cd dntutorial

Before you continue, spend some time playing around in Terminal. There are a couple things you will need to know. First, while you know how to go into a directory, I haven’t shown you how to get out of a directory. If you use the command

cd ..

it will take you up one level into the folder you were in before. If you get lost while jumping around directories, using the command cd on its own will take you back to your home folder.

As an exercise, list the contents of your Documents folder and your Pictures folder. You should also look up the mkdir command on Wikipedia.

You may find this difficult. Keep at it, keep trying different things until you’ve listed the contents of those directories. With the commands I’ve shown you, you can’t mess anything up, so keep playing around until you finish the exercise. If you’re totally stuck (and you’re not totally stuck until you’ve spent at least half an hour on it), post in the comments and we’ll help you out.

Ok, that’s it for Terminal! Now if you’re ever stuck in a lab with dinosaurs surrounding you, you’ll know what to do.

Ready to move on? Continue to Part 2B: The Text Editor

  1. No comments yet.
  1. No trackbacks yet.