# The Command Line

### KEY TERMS

* **File Explorer:** part of the GUI that allows us to find and interact with the files on a computer
* **command line:** a way to give written instructions to a computer
* **command line interpreter:** a program that turns command line keywords into instructions that a computer can understand and execute
* **Command Prompt:** a command line interpreter mostly used on Windows computers
* **directory:** a place for storing files or other directories (similar to a folder)
* **path:** a description of where a file or directory is located on a computer

{% hint style="warning" %}
Note: The instructions and the images in this section refer to a Windows computer.
{% endhint %}

In order to use computers to help us accomplish tasks, we have to be able to give computers instructions. For example, if we wanted to open a file called `hello.txt` in the Documents folder on our computer, we would first have to tell the computer how to find it.&#x20;

To open the file, we could click on the **File Explorer** icon to see all of our files, double-click on the Documents folder, and then double-click the `hello.txt` file icon. Clicking on folders and files with your mouse is one way to navigate your computer and give it instructions.

![Figure 1: File Explorer](https://1640775911-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_QqIZ-ZgXL5GekACpb%2F-Ll-Ig4dtkdDhG1yxtAH%2F-Ll-IlqA8ecK2vPauIww%2F1.PNG?alt=media\&token=d2909938-c921-45a4-b984-3e75e90d2c2a)

![Figure 2: We can open hello.txt by using our mouse to find and click on the file.](https://1640775911-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_QqIZ-ZgXL5GekACpb%2F-Ll-It_do47BhxXlqX-w%2F-Ll-Ivv8hh1dBvaZ6VVW%2F2.PNG?alt=media\&token=beb781e1-c033-4103-9c40-97db3d24ef7c)

Another way to communicate with your computer is through the **command line**, which uses written commands instead of visual icons.

The **Command Prompt** is a **command line interpreter**, which means that it can take commands written by a user and interpret them so that the computer can execute those instructions. Using Command Prompt, we can enter specific, predefined keywords that the interpreter understands to give the computer written instructions.

When we open up the Command Prompt, it should look something like this:

![Figure 2: The Command Prompt](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LI4U9TmkUP7l74ZHrH0%2F-LJK_m7Xxv7q--cJ5E3x%2F-LJKZ9q2_r2HSRVYRHW7%2Fimage.png?alt=media\&token=a6d5723a-9410-4f40-a36c-8730028017b6)

To find and open files using the Command Prompt, it is important to know which directory we are currently in. A **directory** is similar to a folder in File Explorer — it can be contained inside of another directory and it can contain other directories or files inside of it. In the Command Prompt example above, we can look to the left of the cursor to see that the current directory we are in is `C:\Windows\System32`. The line `C:\Windows\System32` tells you the **path** to that directory, separated by backslashes — the `System32` directory is located in the `Windows` directory, which in turn is located in the `C:` directory.

{% hint style="warning" %}
Note: Your Command Prompt may not begin in the same directory as the example.
{% endhint %}

If we want to navigate to a different directory, we can use the the keyword `cd`, which stands for 'change directory.' We can use this command in one of two ways.

* Moving up one directory: This is the equivalent of clicking the back button in File Explorer to exit a folder and return to the folder that contains it. To do this in the command line, we can write: `cd ..` . Note that this command is relative to the directory you are currently located in, which means it can only be used to move one directory up from the current directory. See Figure 3 for an example.
* Moving down one directory: This is the equivalent of double-clicking on a sub-folder inside the current folder to enter the sub-folder. To do this in the command line, we can write: `cd SUBDIRECTORY`. Note that you should replace `SUBDIRECTORY` with the name of a valid subdirectory contained by the directory you are currently located in. See Figure 4 for an example.&#x20;

{% hint style="info" %}
It doesn't matter whether we use a forward slash (/) or backslash (\\) here; the computer will recognize both.
{% endhint %}

![Figure 3: cd ..](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LI4U9TmkUP7l74ZHrH0%2F-LJK_m7Xxv7q--cJ5E3x%2F-LJK_Gol-tssj30r6uN0%2Fimage.png?alt=media\&token=7c431d84-6fd2-4ad3-a725-5606280c5ba9)

Figure 3: The command `cd ..` allows us to move up one directory. In this example, we are exiting the `System32` directory and moving up to the directory that contains it, which is the `Windows` directory.

![Figure 4: cd SUBDIRECTORY](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LI4U9TmkUP7l74ZHrH0%2F-LJLAG-wlxyPxTuCtihH%2F-LJLAGwVsvMXNSb2nhJB%2Fimage.png?alt=media\&token=62faa59e-6041-479d-be3a-ce387ae04f2d)

Figure 4: The command `cd SUBDIRECTORY` allows us to move to a subdirectory of the current directory.

The Command Prompt also allows us to do a lot of other things besides navigating through directories! For example, we can use the command line to run a program. A **computer program** gives the computer a set of instructions and tells it to complete them. The command prompt can also be used as a text editor — a type of program that allows us to create and edit text files. One text (and style) editor you might be familiar with is Microsoft Word. In this course, we will be teaching you how to create and run basic programs using a programming language called Python. One way to create and run these programs is using the command line.&#x20;
