Introduction to the Command Line Interface in Mac and Linux
This guide walks through how to navigate inside of the command line interface for Mac and Linux systems. This is the tool that we'll use throughout this course, so it's important to have a basic understanding of how it works.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In this guide, we are re going to see how to work with the command line system in Mac and Linux.

If you're watching this from a Windows PC, I'd highly recommend using an installation such as virtual box with Linux installed on it or a tool like c9.io, as Rails doesn't work that well with Windows. This doesn't mean you can't use Windows, rather, you will be more successful using tools that better support Rails.

This will be a basic introduction to the command line.

If you've never worked on a command line in Mac, it's called the terminal.

How to Access the Terminal

To open it, look for it at the bottom of your screen in the app menu bar. Another way to open it is to go to your Launchpad and type "terminal" in the search box. Click on the icon, and this should open up your terminal.

Yet another way to open the terminal is to go to the Finder button at the bottom of your screen, click on applications and use the search function there.

If you want to keep the Terminal in your dock permanently, open it and then it and you will see it in the dock. Simply right-click on the terminal icon and choose Options>Keep in Dock.

Now, if you have the terminal open, the cursor is at the bottom. Since it's not the most intuitive place, lets type clear so the cursor comes to the very top.

Direct Access

If you've never worked with command line interface it can seem a little intimidating. The command line is simply a direct connection to your system. Every time you open your browser or any other application like Photoshop, you're actually interacting with the command line interface, but the program is doing it for you. Now, you can do it yourself by using the terminal. In this course, we'll be doing everything we want through the terminal. We will be using it in every single guide. The terminal will allow us to create our app, see our file system, and do many other things, so it's important you become familiar and comfortable with it.

Basic Commands

Now, we're going to go through some basic commands.

The first one is cd which stands for change directory.

If you want to see everything in your directory you will type cd then hit tab.

If you type cd ~/ it will bring up all the directories.

The terminal has an auto-complete feature, so when you type the first few letters of the directory name and hit tab, it will complete the directory or file name for you.

When you hit enter it will take you to that directory.

The next basic command is pwd which stands for present working directory. It will tell you the current directory you are in.

If you want to see all the files in the directory, type ls. This will bring up the complete list of files.

Customizing your Terminal

If you think the look and feel of my terminal is different from yours, don't worry as I've customized mine to look the way I want. To customize, click on "Terminal" on left-hand corner of your screen and choose "Preferences." This should bring up a host of choices for you. Feel free to play around with it to get familiar with this tool.

Working with the Command Line

Next, try to move to another directory and list all the files in it.

The syntax is cd directory-name then ls

To create a new directory, use the command mkdir which stands for 'Make directory.' This is the equivalent of creating a new folder through your file system.

The syntax is mkdir directory-name

I've created a directory called 'introduction-to-command-line', and you can see it in the list now.

So, these are some basic commands to create and navigate through directories in the command line.