Learn to love the Terminal



Many of us are used to using GUIS (Graphical User Interfaces), but learning how to use the CLI ( Command Line Interface ), is essential for programming. Common names include the Shell, CLI, Terminal and Console. But exactly what is the Command Line? At it’s core, it’s simply the place where you type commands to the computer. Wikipedia defines the Terminal this way:

“A command-line interface (CLI) is a means of interaction with a computer program where the user (or client) issues commands to the program in the form of successive lines of text (command lines). A command-line interface is one type of text-based user interface.”

On a Mac, launch the Terminal from the utilities folder inside of your main Applications folder. Apple Mac OS X[4] and many Linux distributions have the Bash implementation of the Unix shell.

On MS Windows users use the Command Prompt or the PowerShell. Android uses a Unix shell derived from Ash with commands from the separate toolbox.

We will be concerning ourselves with the Mac side of things.

Most commands have three parts and start with the $ symbol.
The Utility or Command Name / The Flags or Options / The Argument(s)

$ ls -1 ~/Desktop

Okay, let's break each part down:

$ is the common symbol for SELECT, which indicates that you’re ready to type commands into the command line. You don’t have to type this, it’s inherited with the prompt.

ls is THE UTILITY. Generally known as “commands” as they are indicating what you want the computer to do. In this case “ls” is the command to list the contents of directories.

-1 is the FLAG or OPTION. This changes or alters how a utility may operate slightly. Usually the default works just fine, but flags allow you to modify them to your liking. They start with one or two dashes. In this case, the option “-1” means one file per line.

~/Desktop is the ARGUMENT to the utility. Arguments are used to define exactly what the utility might need to know for certain actions, and there is no clear default setting. In this case, the argument tells the utility which directory to list.

To get a list of all commands, type this:

$ man command

FYI: Man means manual.

Remember guys, you're ready to go when you see the '$' in the terminal. You're now ready to code.

ls Lists what is in the current directory.

pwd Print Working Directory, gives you the full path of where you are.

cd Change Directory, allows you to go to another directory, remember you have to define this utility with a path, for instance cd ~/my_machine/new_path.

cd .. Change Directory, but you want to go up a directory vs. down a directory.

irb Interactive Ruby, which you have to have installed. Now watch for the prompt! When launching the irb, the prompt will change from '$' to '>'. That means you have to exit irb with control D, to get back to the former context.

mkdir Make Directory, allows you to make a folder.

rails new app_name Rails New Application Name, after you've installed Rails, this command will create the entire directory structure of a rails application. Rails is the Gem, App_Name is just a placeholder for the name you'll be giving the app.

rails server or rails s Rails Server which launches a local server, you then open a browser window and type: localhost:3000 and bam you've got a local version of your work.

exit Exits a terminal window.

man -k "topic"Manual Lookup Topic, looks up and displays what you're looking for in quotes.

If you ever get stuck, go online to any one of these resources. Don't be afraid to ask for help!

Stack Overflow is a great place to post a question.
Wiki List of Unix Commands is a great place to read about the history and the use of the command line.
Mac User List of Unix Commands
ss64.com is another great for resource for everyone.