Difficulty: Beginner
Estimated Time: 10 minutes

Welcome to the command line interface. In this brief lesson, you'll create files and directories, read files, navigate around directories, and install software packages. You'll also turn the output of a command into a text file and send output of one program to another.

This lesson is adapted from my book Small Sharp Software Tools, published by the Pragmatic Programmers LLC. All content used by permission. If you like this lesson, pick up your own copy of the book today!

In this lesson, you got a taste of basic command-line usage. You know how to navigate around your home directory, you can create basic text files and directories, and you can install programs with the package manager.

To learn more great command-line tricks, pick up your copy of Small Sharp Software tools today. It has many more lessons just like this one.

Getting Started with the CLI

Step 1 of 14

You Are Here

When you first open the command line interface, or CLI, you'll be presented with something that looks like this:

[email protected]:~$

his is the prompt, and it's the CLI's way of telling you it's ready for you to type a command. This prompt is from the Ubuntu operating system. If you're on a Mac, your prompt might look like this:

d184018798b0:~ root$

These prompts may look cryptic at first, but there's valuable information here. The prompts in these examples show the username (brianhogan), the computer's hostname (puzzles), and the current directory, which is represented by a tilde (~), which always refers to your home directory.

When you open the command line interface, you'll be placed in your "home directory".

Your home directory is where you'll find your documents, music, and settings for your programs. You have total control over your home directory. You can create and delete files and directories, move things around, and even install whole programs without administrative privileges. When you launch the CLI, it'll open the session in your home directory.

The computer's disk stores files in a hierarchy of folders, or directories, which we call the file system. When you use the GUI, you click on a folder to open it and see its contents, and an indicator at the top of the GUI window tells you where you are on the file system.

Your prompt may tell you what directory you're currently looking at. But there's a more clear way to tell, and that's with the pwd command, which stands for "print working directory."

At the prompt, type

pwd

The command prints the full path to the current directory to the screen:

/home/scrapbook

Using pwd is a good way to make sure you're always in the directory you want to be in before you run a command.