Boston Python Workshop 5/Friday/Windows terminal navigation

From OpenHatch wiki
Jump to: navigation, search

There are two commands that we'll be using at a command prompt to navigate the filesystem on your computer:

  • dir
  • cd

dir lists the contents of a directory.
cd moves you into a new directory (it stands for "change directory").

Let's practice using these commands.

[edit] Open a command prompt:

  • On Windows Vista or Windows 7: click on the Start menu (the Windows logo in the lower left of the screen), type cmd into the Search field directly above the Start menu button, and click on "cmd" in the search results above the Search field.
  • On Windows XP: click on the Start menu (the Windows logo in the lower left of the screen), click on "Run...", type cmd into the text box, and hit enter.

[edit] Practice using dir and cd

Before you practice these commands, let's make sure you are really at a terminal prompt. Recall that a terminal prompt will look like C:\ and a Python prompt will look like >>>. Make sure you are at a terminal prompt and not a Python prompt; if you are at a Python prompt, you can type exit() on a line by itself and then hit enter to exit Python and return to a terminal prompt. Great!

Type each of these commands and hit enter:


This lists all the files in your home directory.

cd C:\

This will change you into the C:\ directory.


This lists the contents of the C:\ directory.

cd Python27

This will change you into the Python27 subdirectory of the C:\ directory.


You should see the names of all the files in C:\Python27, including your python.exe application.

cd ..

.. means "parent directory", so this command moved you up to the parent directory. You were in C:\Python27, so now you are in C:\, the root directory.


This lists the contents of the root directory, confirming where you are.

  • You can use Tab to auto-complete directory and file names. So from inside the root directory, if you type cd Pytho and hit Tab, the command prompt will auto-complete the directory name, and you can then hit enter to change into the C:\Python27 directory.
  • The command prompt maintains a command history. You can use the up arrow to cycle through old commands.
  • Note that the text that makes up the command prompt changes as you move around directories. The command prompt will always give the full directory path to your current directory.

[edit] Success!

You've practiced using dir and cd to navigate your computer's filesystem from the command prompt.

« Back to the Friday setup page

Personal tools