Command Prompt

The following is basic guide and tutorial to the command prompt. Windows and Linux are explained. Mac OS is not covered explicitly but it will be very similar to Linux. If you're on a Mac, assume the Linux instructions will work and if they don't, use Google to find and tweak the command to make it work on Mac.

Official class videos...
[ Tutorial Part 1 ]
[ Tutorial Part 2 ]


What Is It?

The command prompt is a text interface to your computer. You are probably used to a graphical interface. You point-and-click at icons and menus and that's how you start applications and make things work. A text interface presents you with only a cursor and you have to type commands to make things work. You may have never used a command prompt, but that's about to change (if you intend to be a computer technologist).


Why Do I Need It?

The command prompt is an absolutely essential tool for any computer technologist. You may never need it as a typical consumer user. However if you want to be a programmer, you have to become an expert at the command prompt. Some things can only be done at the command prompt. Some things are just easier at the command prompt. Over time as you get good with the command prompt, you will choose to do some things at the command prompt simply because of personal preference. Most good programmers are faster at the command prompt than they are with a Graphical User Interface (GUI)

It's important to know is this, the GUI you are used to is NOT the computer and is NOT the operating system. It is a layer of convenience placed on top of the operating system to make common and non-technical tasks easier. The GUI is an abstraction of what is really going on behind the scenes. Also it's very important to realize that what you can do in the GUI is only what the makers of the GUI let you do.

The command prompt is closer to the computer and the actual operating system. As such, it's far less constrained and a potentially more powerful way to interact with the operating system. At the command prompt, you decide what is possible, not the makers of the GUI.


Operating System Differences

Each of the three major operating systems will behave differently in the GUI and the command prompt. This is owing to the target market and purpose of the operating system. Consider...

  • Windows: A relatively insecure, hybrid home and business operating system. The jack-of-all-trades and master-of-none operating system (except gaming, Windows still leads in gaming).
  • Mac OS: A relatively secure, almost exclusively consumer personal-use operating system that has been adapted to niche creative applications and business applications. The master of it-just-works and too bad if you don't like the way it works.
  • Linux: An inherently and highly secure server and industrial-strength operating system that has been adapted to personal use in some cases (sort of). The master-of-servers, computer science, and research, and too bad if you don't understand it because we're not telling you how it works. It's open source, you figure it out.

Keeping in mind who each OS is made for, here is a breakdown of the power and flexibility between systems.

  • Windows GUI: Powerful and flexible. Arguably the best blend of power and ease of use with flexibility in mind.
  • Windows Command Prompt: Little power or flexibility. Almost useless. However, Windows has a better command prompts (based on Linux) which you can install such as powershell, MinGW, Cygwin. Feel free to install any of them for use in class and for all your programming needs.

  • Mac OS GUI: Very Powerful but with almost no flexibility. Don't like it? Too bad.
  • Mac OS Command Prompt: Very powerful. Like Linux, built on Unix, so has many similarities and is almost as hard to use.

  • Linux GUI: It's a barrel of monkeys. Rabid, insane monkeys. Don't like it? Too bad. Here is the source code, you fix it.
  • Linux Command Prompt: Ultra powerful. Very complex. This is where the magic happens. Good luck, you'll need it.

Whatever your choice of operating systems, you're not escaping the command prompt if you intend to be a computer technologist. If you do not master the command prompt your career is over before it begins. So best get to it...

Getting Started

On Windows go to the start menu, search for "command" and you will get an item called "command prompt." Click it and it will start something like this:

Windows command prompt

On Linux and Mac, start the Terminal and it will look something like this:

Linux command prompt

In both cases you have a prompt where you can now type commands. First thing to note is both prompts tell you where you are in your computer. The Windows prompt tells you that you are on the C drive and in the Windows directory. The Linux prompt tells you that you are in the home directory (that's the ~ character) for the user named "alex" on a computer named "alex-laptop".

To interact with the terminal type commands and press Enter. For example to list the contents of a directory type dir on Windows and ls on Linux and Mac. You will then see a listing of the files in the directory showing at the command prompt. This will show you the same thing as if you opened a file explorer window and clicked on a folder.


Parameters and Switches

Most commands allow you to give them extra information (parameters) or turn features on and off (switches). For example, the simple dir or ls command only list basic file information for the current directory.

Windows Example: Suppose you are on C:\Windows but you want to list the contents of C:\temp without changing the current directory. Type dir c:\temp and you will see the contents of C:\temp. In this case, the c:\temp part of the command is a parameter.

Suppose you want to list hidden files that might be there but are not normally visible. Type dir /a and you will see the hidden files. The /a part is a switch. It turns on the "all" feature.

You can also combine these like so dir c:\temp /a

Linux/Mac Example: Suppose you are on ~ (your user directory) but you want to list the contents of /tmp (a directory called tmp on the root of the drive) without changing the current directory. Type ls /tmp and you will see the contents of /tmp. In this case, the /tmp part of the command is a parameter.

Suppose you want to list hidden files that might be there but are not normally visible and also you want to see file details not normally presented. Type ls -al and you will see the hidden files along with detailed files information. The -al part is actually two switches. The -a turns on the "all" feature to see hidden files and the The -l turns on the listing details. When you use multiple switches its common to put them together like so -al

You can also combine all that like so ls -al /tmp


Basic Commands You Will Need

The following is an excellent basic tutorial: Django Girs Intro To The Command Line. For all programming classes you will be expected to know and be able to use the commands in the Summary section of that tutorial. You will also be expected to know and use all several more commands, switches, and parameters which will be covered in lectures.

In addition, you will use Git which has an extensive command line interface. Git and this tutorial will be covered in lectures.

Here are a few more general resources to get started: