Don't already have an account? Create an account.
By creating an Ordinary Coders account, you agree to Ordinary Coders' Terms and Conditions.
If you already have an account, login instead.
Post a Comment
Join the community
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
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:
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
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
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
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
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.
User-Macbook:desktop user$ mkdir code
User-Macbook:desktop user$ 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.
1. Which of the following programs will give you access to a CLI?
"A" is correct. Command Prompt/Terminal provide access to a CLI on their respective platforms. Finder/File explorer can accomplish some of the same things as Command Prompt/Terminal.
2. Which command will show all current folders and files in a given directory?
"B" is correct. "ls" stands for list and "dir" stands for directory. The command "ls" will show the contents of the current directory for macOS and "dir" will do the same for Windows Command Prompt.
3. You are currently in the desktop directory. How do you return to the parent folder?
"B" is correct. To return to the parent folder, meaning the folder that contains the current folder, enter "cd..".