top of page
A beginner's guide to the

Command Line

What even is the "command line"?

The command line is an interface to the computer that allows humans to communicate with the machine. This interface is "text based" which means in order to submit commands, you must directly type them in. This sounds complicated, but it these text commands provide the same function as they would with clicking the screen with the mouse! 

The command line is not user-friendly, however it is a very powerful tool and can extremely efficient once learned.

Step One: How to Access the Command Line

In order to access the command line, you must open a command shell. In Windows, you may search in programs for "Command Prompt". In Mac, you will search for "Terminal" in programs. For the sake of this blog, we will be using Terminal on Mac to walk you through the command line. 

Once you search for Terminal in Applications, you will be greeted with this window seen on the right. 

This Terminal is the text equivalent of opening Finder (or File Explorer for Windows) and having it display the "Home" folder.

What does this line of code mean?

  • Victorias-Macbook-Air: This is the name of the machine we are currently working on. Your machine name will likely be different, unless we have the same name :-)​​

  • ~: The "~" is a handy symbol in the command line that represents being in the home directory.

  • victoriapressman: This is the user you are logged in as.

  • $: The dollar symbol follows the user which denotes that anything following is where you will type your commands.  

Step Two: How to Use the Command Line Basics

Anchor 1

Now that you have the command line open, what do you do with it?

One of the first commands you can try on your terminal is "pwd". This stands for "print working directory". This prints the current directory or folder that you are in. 

If you would like to access a certain directory, you will type in the command "cd" (short for command) followed with a space and the folder you want to go into. For example, I want to access my Documents directory. I type "cd documents" as shown on the right.

 

 

Great. Now I'm in my documents folder. How do I do anything with it? In order to access what documents are in this folder, type "ls" which will list all files in that folder. 

Think of the ls function as the equivalent of opening the Documents folder in Finder and viewing all of the file contents.

Ok. I'm in the documents folder, I really want to view my "Personal" folder. I would type "cd Personal" and now I am in this directory. I type "ls" to view what files are in this directory, and I see that my resume is in there! To open this file, I type "open" followed with the file name and extension and it will automatically open the file.

 

 

 

 

 

 

 

 

 

Once entering this command, the Resume.doc file is opened in another window as seen to the right. For security reasons, I blurred my resume :)

If you ever get lost and want to get out of the current folder you are in, you can type "cd ~" and return back to the home folder to restart. 

Step Three: Paths

Now that you know the basics of using the command line, let's talk about some of the guidelines to prevent frustrations later on.

Using the example above, let's say you're still in the Personal directory. You want to open the "text.txt" file in your Desktop. You follow these same instructions and go ahead and type "open text.txt", but an error comes up.

File doesnt exist? Why? Well, think about the file path of the "text.txt" file. You are currently in the Personal folder that is in the Documents folder. If you were to open this file in Finder, you would not be able to access and open the text.txt file unless you move out of the Personal folder, out of the Documents folder, and into the Desktop folder where the text.txt file lives.

You can simplify this process by utilizing "." shortcut.

. represents the current folder (Personal)

.. represents the parent folder (Documents)

... will move even further if possible

However, if you know the direct file path to text.txt, you can bypass all of this by typing:

1. open ~/desktop/text.txt

 

(Remember ~ is a shortcut that takes you to the home directory). 

This opens the text.txt document in one command as shown to the right!

You may use direct file paths for cd as well as ls as well. 

Step Four: File Commands

Now that you've had some practice accessing files using the command line, you can start using it to do many of the same functions you can in Finder by using the correct command. 

Other commands you can use and play around with are shown to the left. This is a very short list of what you are capable of using in the command line! If you want a more extensive list, click here. 

If you would like to learn more about what a command does, you can type "man" followed with a space and the command you want to learn more about, and terminal will list information about it. 

bottom of page