How To Open And Run Commands In The Terminal (Beginner Friendly)

by DM
what is a computer terminal command line1

It looks scary and somewhat intimidating, but the Terminal is rather a simple affair to master.

This post will introduce you to the commands you need to start navigating the Terminal. Later on, we will use the Terminal to start local server environments when creating applications!

What is a Terminal?

A Terminal is a text-based prompt (Command Line Interface) that helps us interact with machines.

Think of it as an X-ray Files on Windows or Finder on Mac, a behind-the-scenes view of the desktop and all the elements you interact with, like folders and files, on your computer.

Although it requires getting a grasp on command codes to run, the advantage of the Terminal is that it provides more access than a Graphical User Interface (GUI).

What is the Terminal capable of letting you do?

From setting up local environments for building and testing applications to increasing the efficiency of navigating and manipulating folders and files, the Terminal is a powerful tool to master.

It’s, also, where you can find your secret files that are not visible unless you know how to look for them!

The Terminal opens in your home directory by default when launching it.

On a Mac this is the same as going through Finder, under location choosing your device, clicking your drive, then selecting the Users folder and clicking on your user profile name.

Opening the Terminal already eliminates all those navigation steps.

How do I open a Terminal?

The easiest way to find your Terminal and open it is by just searching for it. Hit cmd + space bar on a Mac to bring up your search and type in Terminal. Likewise, use the search feature in the menu for Windows.

how to open terminal 2
The Terminal application on a Mac as of writing.

Of course, you can also look around in your applications. Most computers come equipped with a built-in Terminal, but there are other Terminal applications available for download online should you want something with more robust features.

We will be using the built-in Mac Terminal – it has worked perfectly well for all applications built so far.


Tip 🤓

How do I change the font size in the Terminal?

Mac: Hold cmd and click either the + (plus sign) to zoom in and make the text larger or the – (minus sign) to make it smaller.

Windows: Hold control and scroll

Note that any changes you make to the font size will persist for the duration of the session. So once you exit the Terminal and re-launch it, the font will revert to its default size.


Now, let’s look at some of the most important starting commands that will allow you to use the Terminal for organizing files and folders without the need to move your mouse at all.

How do I run a command in the Terminal?

To list all the folders located within your User profile, the default location your Terminal opens up into and, so, your “main directory”, execute the ls command (list items).

You will get something like this:

undersanding terminal command line 3

Breaking down the structure of the entered command and response is as follows:

  • Line to enter a command into

My-device:~ User$

Your command comes after the dollar-sign ($)

The squiggly line ( ~ ) stands for your main directory. Read the line as “You are on My-device in the main directory of the User profile”.

  • The response of an executed command is, typically, directly below the command line

In the example, we get a list of all directories inside of the main (User) directory after running ls.

  • Once a command is executed, the next line to enter a command automatically appears below the response.

Note

A “directory” is a system of folders AND files. Think of it as a cabinet where you can have individual documents as well as file folders containing multiple documents.

So the list provides both individual documents as well as folders containing other files and folders.

Tip: Long responses push the command line all the way to the bottom. To clear the shell and bring the command line on the top do cmd + k on a Mac.

Terminal and Command Line Tools

changing directories in the terminal 4
Going from the main directory ( ~ ) to the Desktop using the “cd” command.

The commands below apply directly on a Mac. For Windows, you might run into some unsupported commands like touch <file.ext> used to create a new file (see below). In such cases, Google is your best friend and, in the create new file case in particular, a Windows workaround can be found here.

lslist of folders and files in the directory you are currently in
cd <directory_name>move forward/backward among directories (cd = change directory)
cd ..back-up one directory
cd ~takes you to the home directory
cd /takes you to the route directory (a level up from your main directory)
pwdprint working directory (find where you currently are)
mkdir <name>make a new directory called [ name ]
touch <file.ext>create a file called [ file ] with the extension of “ext” (if no extension is provided, the file defaults to a text file)
man lspulls manual with a list of the commands (type q to exit)

Be very careful and DO NOT ATTEMPT the following commands unless it is to work with the dummy files and directories you created while practicing the above commands.

The “rm” command will REMOVE, as in wipe out from virtual existence, any directories specified including, potentially, the system root directory.

rm <file_to_remove>remove files forever (there’s no trash bin)
rmdir <dir_to_remove>removes an empty directory
rm -rf <dir>forces removal of a directory including every single file, folder, sub-folder, etc. it may contain

Tip

If your file or folder has a name that includes spaces, wrap it in quotations.

Ex: “My file”.html