The command line (or Terminal) is an invaluable, text-only view of your computer. As developers we use it extensively to install and configure our Django projects.

Installation

On a Mac, the command line is found in a program called Terminal located at /Applications/Utilities. To find it, open a new Finder window, open the Applications folder, scroll down to open the Utilities folder, and double-click the application called Terminal.

On Windows, there is a built-in command line program but it is difficult to use. I recommend instead using Babun, a free and open-source command line program. Click on the “Download now” button on its website, double-click it to install Babun, and upon completion drag the installer to the Recycle Bin. To use Babun go to the Start menu, select Programs, and click on Babun.

Common commands

While there are many possible commands we can use, in practice there are six that we will use most of the time:

  • cd (change down a directory)
  • cd .. (change up a directory)
  • ls (list files in your current directory)
  • pwd (print working directory)
  • mkdir (make directory)
  • touch (create a new file)

Open your command line and try them out. Here’s what I see on my computer:

$ cd ~/Desktop # change into the Desktop
~/Desktop $ pwd
/Users/wsv/desktop
~/Desktop $ ls
Code Sites Music Pictures
~/Desktop $ mkdir new_folder
~/Desktop $ ls
Code Sites Music Pictures new_folder
~/Desktop $ cd new_folder
~/Desktop/new_folder $ touch index.html # create a new file called index.html
~/Desktop/new_folder $ ls
index.html

Warning!!!

For the most part, programmers are very helpful online. But occasionally someone tries to take advantage of an inexperienced Terminal user and suggests running a particularly nasty command. The command line is so powerful that if you ask it to delete your computer, it will happily do so without any warnings! Therefore, do not run commands you find on the internet unless you trust its source. Never run a command just to see what it does.

In particular, here are two commands that you might come across online, but should never, never, never actually run. They can and will destroy your computer.

$ sudo rm -rf /

This command tells the computer to delete every single file on the computer. Upon completion, your computer will be empty. If you turn your computer off, it will not start unless you reinstall an operating system.

$ :(){ :|:& };:

This seemingly benign command is known as a fork bomb. It will use up all the available resources on your computer and cause it to freeze or crash. Fortunately, restarting your computer should bring it back to normal.

Further Resources

Two good free resources for further study are the Command Line Crash Course and CodeCademy’s Course on the Command Line.