1: Getting started with the command line interface

So far, you have learned front-end development or the practice of using HTML, CSS, and JavaScript to display content to users. In the next section of this tutorial, you will take on back-end development or the logic and functionality of the site.  While many developers specialize in one or the other, this course seeks to provide a solid foundation in both. A developer skilled in both server and client side development is called a full-stack developer given their ability to handle both the operation and appearance of the site. 


What is a command line interface?

A command line interface (CLI) is a program that accepts lines of text to process commands.  On Windows, both the Command Prompt and Windows Powershell provide a CLI.  On macOS, Terminal provides a CLI. 


What can you do with a CLI? 

To begin, these programs offer the same commands as programs like Windows File Explorer and macOS Finder where you can create new files and folders and organize whether a picture is located in your desktop, documents or downloads. 


How will we use CLI?

For our purposes, we will need a CLI to setup a virtual environment, install and create a Django project, and run our development server.  Virtual environments are used to isolate projects from other files on a computer to prevent overlapping or conflicting packages.  Basically, a virtual environment will act as a special container where we will install Django.  Any other packages we install in the virtual environment will only be accessible in the virtual environment unless purposely installed elsewhere.  

Follow us @ordinarycoders

2: CLI Basics

CLI Basics

Before we install our virtual environment let's go over the basics of the command line interface. To begin, search for the program Terminal on macOS or Command Prompt on Windows under your computer's apps then open the program to follow along. When you first open the program you will see one of the following lines:

macOS Terminal

User-Macbook:~ user$

Windows Command Prompt


For macOS users, User/user is the name of the current user and Macbook is the name of the device being used. For Windows users, C represents the main hard disk partition that contains the operating system and related files.  Users is the folder that contains all users for the device.  Owner is the current user for this device.  


List command for macOS Terminal

User-Macbook:~ user$ ls

List command for Windows Command Prompt


The first command we will enter is the list command. For macOS we will enter ls and for Windows we will enter the command dir. Both commands lists all files and folders in the current user directory. 


Change directory command for macOS Terminal

User-Macbook:~ user$ cd desktop

Change directory command for Windows Terminal

C:\Users\Owner>cd desktop

Next we will try out the cd or change directory command.  This will change our current directory from Owner to Owner > desktop.  All the files listed are available on your actual desktop.


Previous command for macOS Terminal

User-Macbook:~ user$ cd ..

Previous command for Windows Command Prompt

C:\Users\Owner>cd ..

To return to the previous directory use cd..; in this case, we return back to the Owner directory.

With just the cd and ls/dir commands, you already have a basic understanding of the CLI and how to navigate your computer.  Let's go over a few more examples. Navigate back into the desktop directory with cd desktop.


Make directory command for macOS Terminal

User-Macbook:desktop user$ mkdir folder

Make directory command for Windows Command Prompt

C:\Users\Owner\desktop>mkdir folder

The mkdir will create a new folder named folder in our desktop directory.  Enter ls or dir to view the folder.


Delete command for macOS Terminal

User-Macbook:desktop user$ del folder

Delete command for Windows Command Prompt

C:\Users\Owner\desktop>del folder

The del command will delete whichever directory/file is specified.  Enter ls or dir to see that the folder has been removed.


Load previous commands in the CLI

CLIs keep a log of commands executed. Use this log to your advantage by pressing the key to restore the last command ran in the prompt. Clicking the key multiple times will continue to load previous commands. Newly opened CLI windows do not have a log until a command is executed.

You will end up running the same commands multiple times throughout this tutorial so remember this command.


Create a folder named code for our future projects

Alright, it's time to make a new folder on our desktop called code that will contain our project folders. 

macOS Terminal

User-Macbook:desktop user$ mkdir code
User-Macbook:desktop user$ cd code
User-Macbook:code user$

Windows Command Prompt

C:\Users\Owner\desktop>mkdir code
C:\Users\Owner\desktop>cd code

Make sure you are in the desktop directory then enter mkdir code to create a new folder called code and cd into it. Before getting started with our Django web app, we will use a Jupyter notebook to go over some basic Python examples. We will learn the origins of Python, how to install Python, and how to create virtual environments for coding projects in the next lesson.

Follow us @ordinarycoders

Quiz Questions

1. Which of the following programs will give you access to a CLI?

2. Which command will show all current folders and files in a given directory?

3. You are currently in the desktop directory. How do you return to the parent folder?

Next lesson

Check out the comments and debug buttons if you get stuck.