I remember the first time I used terminal, which is Mac’s version of the command line. It was scary. In fact, I was scared or at least nervous for the first month or so as I got comfortable and familiar with it. It was so foreign and different that I was worried that I would do something and not be sure how to undo it. I’m here to help you feel comfortable and confident using terminal.
The best way to learn and feel comfortable is by using it. Trust me. The more you use it the more familiar and comfortable it will feel. So, let’s get started.
First, you need to open it up. Go to: Applications > Utilities > Terminal
Double click on Terminal and you will be brought to something like this:
Yours won’t look exactly like mine as I’ve customized the way mine looks. I’ll show you how to do that later. But, for now, let’s learn a few commands and do a few things.
The first and most important commands you’ll learn are related to your directories - how to view the contents and change your location. You’ll use at least one of these commands pretty much every single time you interact with the command line.
pwd - tells you where you are (you’re inside a folder and this is showing you which folder you’re in)
open . (
start . on pc) - opens up whatever you tell it to.
ls - lists all folders and/or documents inside the folder you’re currently in
cd - change directory: type cd and then the name of the folder you want to move into.
cd .. - sends you back to the previous directory
You may be wondering why you should go through the process of learning to use the command line. If you plan to do rails development, or pretty much any development you’ll need to learn to use the command line. The other benefit of the command line is that you can run way more commands in the command line than you could visually. For example,
ls -a will list all files (including hidden files).
Let’s walk through a typical use case.
- You open terminal.
- Where am I? You type
pwdto see where you are. Now you know you’re at your root directory.
- What folders/files are available to me? You type
lsto see all folders and/or documents are there. You see one of the folders is “code” and that’s where you want to go.
- Let’s move into the “code” file. You type
cd codeto move into the code folder.
- Am I in the code folder now? You type
pwdto see where you are. Now you know you’re in the code directory.
- What folders and/or documents are in the code folder? You type
lsto see what’s inside the “code” folder. You seem to remember you created a “ruby on rails” folder. You see a folder named “rails” and realize that’s the one you’re looking for. You want to move into that folder.
What do you think is the next thing you will do to move into the “rails” folder? You got it. You type
The command line isn’t so hard after all. :)
If you want to learn more here is a free command line crash course.