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/OSX

$ 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 Learn Python the Hard Way, 5th Edition

When you buy Learn Python the Hard Way, 5th Edition directly from the author, Zed A. Shaw, you'll get access to the digital content for all 60 exercises, plus all 60+ videos that are normally sold separately. You'll also have access to direct help from Zed via Discord chat and live streams on special topics when I have time.

$29

Buy Learn Python The Hard Way, 5th Edition

Learn JavaScript the Hard Way

If you want to learn to be a Web Developer then my new Learn JavaScript the Hard Way course is a great choice. It's currently out as an Early Access release and already has more content than the Python Course, with even more content coming at a 80% discount from the final price.

Buy Learn JavaScript the Hard Way