Introduction to the command-line interface

For readers at home: this chapter is covered in the Your new friend: Command Line video.

It's exciting, right?! You'll write your first line of code in just a few minutes! :)

Let us introduce you to your first new friend: the command line!

The following steps will show you how to use the black window all hackers use. It might look a bit scary at first but really it's just a prompt waiting for commands from you.

Note Please note that throughout this book we use the terms 'directory' and 'folder' interchangeably but they are one and the same thing.

What is the command line?

The window, which is usually called the command line or command-line interface, is a text-based application for viewing, handling, and manipulating files on your computer. It's much like Windows Explorer or Finder on the Mac, but without the graphical interface. Other names for the command line are: cmd, CLI, prompt, console or terminal.

Open the command-line interface

To start some experiments we need to open our command-line interface first.

Windows

Go to Start menu → All Programs → Accessories → Command Prompt.

Mac

Go to Applications → Utilities → Terminal.

Linux

It's probably under Applications → Accessories → Terminal, but that may depend on your system. If it's not there, just Google it. :)

Prompt

You now should see a white or black window that is waiting for your commands.

OS X and Linux

If you're on Mac or Linux, you probably see $, just like this:

command-line

$

Windows

On Windows, it's a > sign, like this:

command-line

>

Each command will be prepended by this sign and one space, but you don't have to type it. Your computer will do it for you. :)

Just a small note: in your case there may be something like C:\Users\ola> or Olas-MacBook-Air:~ ola$ before the prompt sign, and this is 100% OK.

The part up to and including the $ or the > is called the command line prompt, or prompt for short. It prompts you to input something there.

In the tutorial, when we want you to type in a command, we will include the $ or >, and occasionally more to the left. You can ignore the left part and just type in the command which starts after the prompt.

Your first command (YAY!)

Let's start with something simple. Type this command:

OS X and Linux

command-line

$ whoami

Windows

command-line

> whoami

And then hit enter. This is our result:

command-line

$ whoami
olasitarska

As you can see, the computer has just printed your username. Neat, huh? :)

Try to type each command; do not copy-paste. You'll remember more this way!

Summary

It's not strictly necessary for this tutorial, but here is a summary of some useful commands:

Command (Windows) Command (Mac OS / Linux) Description Example
exit exit close the window exit
cd cd change directory cd test
cd pwd show the current directory cd (Windows) or pwd (Mac OS / Linux)
dir ls list directories/files dir
copy cp copy file copy c:\test\test.txt c:\windows\test.txt
move mv move file move c:\test\test.txt c:\windows\test.txt
mkdir mkdir create a new directory mkdir testdirectory
rmdir (or del) rm delete a file del c:\test\test.txt
rmdir /S rm -r delete a directory rm -r testdirectory

These are just a very few of the commands you can run in your command line, but you're not going to use anything more than that today.

If you're curious, ss64.com contains a complete reference of commands for all operating systems.

Ready?

Let's dive into Python!

results matching ""

    No results matching ""