# Using Terminal/Shell/Command Line

{% hint style="info" %}
In these instructions, the term "Terminal" will be used to refer both to the terminal program, the shell it is running, and the command line. If you know that this is a simplification, you probably don't need these instructions.
{% endhint %}

## Opening the Terminal

* **macOS**: Open Spotlight (Cmd + Space), type "Terminal", and press Return.
* **Windows**: Open Windows Search (Win), type "Terminal", and press Enter.

A window will open with text similar to this:

```bash
~/Documents $ 
```

## Running Commands

The commands are run by typing them at the bottom of the text in the window - after the "$" sign. Type  (or copy-paste) the following command and press Return/Enter:

```bash
echo "I am using the Terminal!"
```

The result should look something like this:

```bash
~/Documents $ echo "I am using the Terminal!"
I am using the Terminal!
~/Documents $
```

## Current Working Directory

Also known as *current directory, working directory, CWD*.

Here is how you can make a copy of the file `sample.txt` and save it as `sample-copy.txt`:

```bash
~/Documents $ cp sample.txt sample-copy.txt
```

When running this command, the Terminal will look for `sample.txt` in (and later write `sample-copy.txt` to) the folder that is set as its *current working directory*.

Let's say that that current working directory, as in the example above, is set to the `Documents` folder within the user's home folder. We can refer to this situation as "I am in the Documents folder" or "the Terminal is open at the Documents folder".

### Checking Current Working Directory

In my case, `sample.txt` is in the `/c/Users/evk465/Documents` folder. I can check whether that is the folder set in the the Terminal with the help of the command `pwd` (short for **p**rint **w**orking **d**irectory):

```sh
~/Documents $ pwd
/c/Users/evk465/Documents
~/Documents $
```

The line under `$ pwd` confirm that the current working directory is indeed `/c/Users/evk465/Documents`

### Changing Current Working Directory

Current working directory can be changed. Let's say that instead of being in the `Documents` folder, I erroneously opened the Terminal at the `Downloads` folder. I can fix that but using the `cp` (short for **c**hange **d**irectory):

```bash
~/Downloads $ pwd
/c/Users/evk465/Downloads 
~/Downloads $ cd /c/Users/evk465/Documents
~/Documents $ pwd
/c/Users/evk465/Documents
~/Documents $
```

{% hint style="info" %}
Instead of typing the name of the directory you can drag it from the file manager and onto the command line. For example, when changing the current working directory, you could type "cd" followed by a space and then drag the "Documents" folder onto the command line. The same applies to files.
{% endhint %}


---

# 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://gitbook.bergelsonlab.com/programming-info/quick-programming-computing-how-tos/using-terminal-shell-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.
