# Introduction to command line

> For readers at home: this chapter is covered in the [Your new friend: Command Line](https://www.youtube.com/watch?v=jvZLWhkzX-8) video.

It's exciting, right?! You'll write your first line of code in just a few minutes! :)

**Let us introduce you to your first new friend: the command line!**

The following steps will show you how to use the black window all hackers use. It might look a bit scary at first but really it's just a prompt waiting for commands from you.

> **Note** Please note that throughout this book we use the terms 'directory' and 'folder' interchangeably but they are one and the same thing.

## What is the command line? <a href="#what-is-the-command-line" id="what-is-the-command-line"></a>

The window, which is usually called the **command line** or **command-line interface**, is a text-based application for viewing, handling, and manipulating files on your computer. It's much like Windows Explorer or Finder on the Mac, but without the graphical interface. Other names for the command line are: *cmd*, *CLI*, *prompt*, *console* or *terminal*.

## Open the command-line interface <a href="#open-the-command-line-interface" id="open-the-command-line-interface"></a>

To start some experiments we need to open our command-line interface first.

**Opening: Windows**

Depending on your version of Windows and your keyboard, one of the following should open a command window (you may have to experiment a bit, but you don't have to try all of these suggestions):

* Go to the Start menu or screen, and enter "Command Prompt" in the search field.
* Go to Start menu → Windows System → Command Prompt.
* Go to Start menu → All Programs → Accessories → Command Prompt.
* Go to the Start screen, hover your mouse in the lower-left corner of the screen, and click the down arrow that appears (on a touch screen, instead flick up from the bottom of the screen). The Apps page should open. Click on Command Prompt in the Windows System section.
* Hold the special Windows key on your keyboard and press the "X" key. Choose "Command Prompt" from the pop-up menu.
* Hold the Windows key and press the "R" key to get a "Run" window. Type "cmd" in the box, and click the OK key.

Later in this tutorial, you will need to have two command windows open at the same time. However, on some versions of Windows, if you already have one command window open and you try to open a second one using the same method, it will instead point you to the command window you already have open. Try it now on your computer and see what happens! If you only get one command window, try one of the other methods in the list above. At least one of them should result in a new command window being opened.

**Opening: OS X**

Go to Applications → Utilities → Terminal.

**Opening: Linux**

It's probably under Applications → Accessories → Terminal, or Applications → System → Terminal, but that may depend on your system. If it's not there, you can try to Google it. :)

## Prompt <a href="#prompt" id="prompt"></a>

You now should see a white or black window that is waiting for your commands.

**Prompt: OS X and Linux**

If you're on Mac or Linux, you probably see a `$`, like this:

command-line

```
$
```

**Prompt: Windows**

On Windows, you probably see a `>`, like this:

command-line

```
>
```

Take a look at the Linux section just above now -- you'll see something more like that when you get to PythonAnywhere later in the tutorial.

Each command will be prepended by a `$` or `>` and one space, but you should not type it. Your computer will do it for you. :)

> Just a small note: in your case there may be something like `C:\Users\ola>` or `Olas-MacBook-Air:~ ola$` before the prompt sign, and this is 100% OK.

The part up to and including the `$` or the `>` is called the *command line prompt*, or *prompt* for short. It prompts you to input something there.

In the tutorial, when we want you to type in a command, we will include the `$` or `>`, and occasionally more to the left. Ignore the left part and only type in the command, which starts after the prompt.

## Your first command (YAY!) <a href="#your-first-command-yay" id="your-first-command-yay"></a>

Let's start by typing this command:

**Your first command: OS X and Linux**

**Your first command: Windows**

And then hit `enter`. This is our result:

command-line

```
$ whoami
olasitarska
```

As you can see, the computer has just printed your username. Neat, huh? :)

> Try to type each command; do not copy-paste. You'll remember more this way!

## Basics <a href="#basics" id="basics"></a>

Each operating system has a slightly different set of commands for the command line, so make sure to follow instructions for your operating system. Let's try this, shall we?

### Current directory <a href="#current-directory" id="current-directory"></a>

It'd be nice to know where are we now, right? Let's see. Type this command and hit `enter`:

**Current directory: OS X and Linux**

command-line

```
$ pwd
/Users/olasitarska
```

> Note: 'pwd' stands for 'print working directory'.

**Current directory: Windows**

command-line

```
> cd
C:\Users\olasitarska
```

> Note: 'cd' stands for 'change directory'. With PowerShell you can use pwd just like on Linux or Mac OS X.

You'll probably see something similar on your machine. Once you open the command line you usually start at your user's home directory.

### Learn more about a command <a href="#learn-more-about-a-command" id="learn-more-about-a-command"></a>

Many commands you can type at the command prompt have built-in help that you can display and read! For example, to learn more about the current directory command:

**Command help: OS X and Linux**

OS X and Linux have a `man` command, which gives you help on commands. Try `man pwd` and see what it says, or put `man` before other commands to see their help. The output of `man` is normally paged. Use the space bar to move to the next page, and `q` to quit looking at the help.

**Command Help: Windows**

Adding a `/?` suffix to most commands will print the help page. You may need to scroll your command window up to see it all. Try `cd /?`.

### List files and directories <a href="#list-files-and-directories" id="list-files-and-directories"></a>

So what's in it? It'd be cool to find out. Let's see:

**List files and directories: OS X and Linux**

command-line

```
$ ls
Applications
Desktop
Downloads
Music
...
```

**List files and directories: Windows**

command-line

```
> dir
 Directory of C:\Users\olasitarska
05/08/2020 07:28 PM       Applications
05/08/2020 07:28 PM       Desktop
05/08/2020 07:28 PM       Downloads
05/08/2020 07:28 PM       Music
...
```

> Note: In PowerShell you can also use 'ls' like on Linux and Mac OS X.

### Change current directory <a href="#change-current-directory" id="change-current-directory"></a>

Now, let's go to our Desktop directory:

**Change current directory: OS X**

command-line

```
$ cd Desktop
```

**Change current directory: Linux**

command-line

```
$ cd Desktop
```

Note that the directory name "Desktop" might be translated to the language of your Linux account. If that's the case, you'll need to replace `Desktop` with the translated name; for example, `Schreibtisch` for German.

**Change current directory: Windows**

command-line

```
> cd Desktop
```

Check if it's really changed:

**Check if changed: OS X and Linux**

command-line

```
$ pwd
/Users/olasitarska/Desktop
```

**Check if changed: Windows**

command-line

```
> cd
C:\Users\olasitarska\Desktop
```

Here it is!

> PRO tip: if you type `cd D` and then hit `tab` on your keyboard, the command line will automatically fill in the rest of the name so you can navigate faster. If there is more than one folder starting with "D", hit the `tab` key twice to get a list of options.

### Create directory <a href="#create-directory" id="create-directory"></a>

How about creating a practice directory on your desktop? You can do it this way:

**Create directory: OS X and Linux**

command-line

```
$ mkdir practice
```

**Create directory: Windows**

command-line

```
> mkdir practice
```

This little command will create a folder with the name `practice` on your desktop. You can check if it's there by looking on your Desktop or by running a `ls` or `dir` command! Try it. :)

> PRO tip: If you don't want to type the same commands over and over, try pressing the `up arrow` and `down arrow` on your keyboard to cycle through recently used commands.

### Exercise! <a href="#exercise" id="exercise"></a>

A small challenge for you: in your newly created `practice` directory, create a directory called `test`. (Use the `cd` and `mkdir` commands.)

#### Solution: <a href="#solution" id="solution"></a>

**Exercise solution: OS X and Linux**

command-line

```
$ cd practice
$ mkdir test
$ ls
test
```

**Exercise solution: Windows**

command-line

```
> cd practice
> mkdir test
> dir
05/08/2020 07:28 PM       test
```

Congrats! :)

### Clean up <a href="#clean-up" id="clean-up"></a>

We don't want to leave a mess, so let's remove everything we did until that point.

First, we need to get back to Desktop:

Using `..` with the `cd` command will change your current directory to the parent directory (that is, the directory that contains your current directory).

Check where you are:

**Check location: OS X and Linux**

command-line

```
$ pwd
/Users/olasitarska/Desktop
```

**Check location: Windows**

command-line

```
> cd
C:\Users\olasitarska\Desktop
```

Now time to delete the `practice` directory:

> **Attention**: Deleting files using `del`, `rmdir` or `rm` is irrecoverable, meaning *the deleted files will be gone forever*! So be very careful with this command.

**Delete directory: Windows Powershell, OS X and Linux**

command-line

```
$ rm -r practice
```

**Delete directory: Windows Command Prompt**

command-line

```
> rmdir /S practice
practice, Are you sure ? Y
```

Done! To be sure it's actually deleted, let's check it:

**Check deletion: OS X and Linux**

### Exit <a href="#exit" id="exit"></a>

That's it for now! You can safely close the command line now. Let's do it the hacker way, alright? :)

Cool, huh? :)

## Summary <a href="#summary" id="summary"></a>

&#x20;Here is a summary of some useful commands:

| Command (Windows) | Command (Mac OS / Linux) | Description                | Example                                            |
| ----------------- | ------------------------ | -------------------------- | -------------------------------------------------- |
| exit              | exit                     | close the window           | **exit**                                           |
| cd                | cd                       | change directory           | **cd test**                                        |
| cd                | pwd                      | show the current directory | **cd** (Windows) or **pwd** (Mac OS / Linux)       |
| dir               | ls                       | list directories/files     | **dir**                                            |
| copy              | cp                       | copy file                  | **copy c:\test\test.txt c:\windows\test.txt**      |
| move              | mv                       | move file                  | **move c:\test\test.txt c:\windows\test.txt**      |
| mkdir             | mkdir                    | create a new directory     | **mkdir testdirectory**                            |
| rmdir (or del)    | rm                       | delete a file              | **del c:\test\test.txt**                           |
| rmdir /S          | rm -r                    | delete a directory         | **rm -r testdirectory**                            |
| \[CMD] /?         | man \[CMD]               | get help for a command     | **cd /?** (Windows) or **man cd** (Mac OS / Linux) |

These are just a very few of the commands you can run in your command line, but you're not going to use anything more than that today.

If you're curious, [ss64.com](http://ss64.com/) contains a complete reference of commands for all operating systems.

## Ready? <a href="#ready" id="ready"></a>

Let's dive into Python!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://djangogirls.nikz.in/basics/intro_to_command_line.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
