Exercise 2: Paths, Folders, Directories (pwd)

In this exercise you learn how to print your working directory with the pwd command.

Do This

I'm going to teach you how to read these "sessions" that I show you. You don't have to type everything I list here, just some of the parts:

  • You do not type in the $ (Unix) or > (Windows). That's just me showing you my session so you can see what I got.
  • You type in the stuff after $ or >, then hit Enter. So if I have $ pwd, you type just pwd and hit Enter.
  • You can then see what I have for output followed by another $ or > prompt. That content is the output, and you should see the same output.

Let's do a simple first command so you can get the hang of this:

Linux/macOS

$ pwd
/Users/zedshaw
$

Windows

PS C:\Users\zed> pwd

Path
----
C:\Users\zed

PS C:\Users\zed>

Note

In this appendix I need to save space so that you can focus on the important details of the commands. To do this, I'm going to strip out the first part of the prompt (the PS C:\Users\zed above) and leave just the little > part. This means your prompt won't look exactly the same, but don't worry about that.

Remember that from now on I'll only have the > to tell you that's the prompt.

I'm doing the same thing for the Unix prompts, but Unix prompts are so varied that most people get used to $ meaning "just the prompt."

You Learned This

Your prompt will look different from mine. You may have your user name before the $ and the name of your computer. On Windows it will probably look different too. The key is that you see the pattern of:

  • There's a prompt.
  • You type a command there. In this case, it's pwd.
  • It printed something.
  • Repeat.

You just learned what pwd does, which means "print working directory." What's a directory? It's a folder. Folder and directory are the same thing, and they're used interchangeably. When you open your file browser on your computer to graphically find files, you are walking through folders. Those folders are the exact same things as these "directories" we're going to work with.

Do More

  • Type pwd 20 times and each time say "print working directory."
  • Write down the path that this command gives you. Find it with your graphical file browser of choice.
  • No, seriously, type it 20 times and say it out loud. Sssh. Just do it.

Buy The Python 3 Edition!

When you buy Learn Python 3 The Hard Way, you'll receive the Python 3 Edition PDF, special access to a paid HTML version, and 12 hours of 1080p video, one video for each exercise. All files are DRM free and you can download them to your computer for offline viewing. Digital Download Only! You do not get a physical book.

$29.99

Buy Digital Download From Zed

Try a a free sample of Learn Python the Hard Way right here, video lectures not included.

Other Buying Options

Buy on Amazon Buy from Barnes & Noble