Using Terminal/Shell/Command Line

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.

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:

~/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:

echo "I am using the Terminal!"

The result should look something like this:

~/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:

~/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 print working directory):

~/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 change directory):

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

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.

Last updated