Chapter 5
Change Directory (cd)

5.1 Do This

I'm going to give you the instructions for these sessions one more time:

  1. You do not type in the $ (unix) or > (Windows).
  2. You type in the stuff after this, then hit enter. If I have $ cd temp you just type cd temp and hit enter.
  3. The output comes after you hit enter, followed by another $ or > prompt.


Source 7: Linux/Mac OSX Exercise 5
  $ cd temp
  $ pwd
  ~/temp
  $ cd stuff
  $ pwd
  ~/temp/stuff
  $ cd things
  $ pwd
  ~/temp/stuff/things
  $ cd frank/
  $ pwd
  ~/temp/stuff/things/frank
  $ cd joe/
  $ pwd
  ~/temp/stuff/things/frank/joe
  $ cd alex/
  $ pwd
  ~/temp/stuff/things/frank/joe/alex
  $ cd john/
  $ pwd
  ~/temp/stuff/things/frank/joe/alex/john
  $ cd ..
  $ cd ..
  $ pwd
  ~/temp/stuff/things/frank/joe
  $ cd ..
  $ cd ..
  $ pwd
  ~/temp/stuff/things
  $ cd ../../..
  $ pwd
  ~/
  $ cd temp/stuff/things/frank/joe/alex/john
  $ pwd
  ~/temp/stuff/things/frank/joe/alex/john
  $ cd ../../../../../../../
  $ pwd
  ~/
  $


Source 8: Windows Exercise 5
  > cd temp
  > pwd
  
  Path
  ----
  C:\Users\zed\temp
  
  
  > cd stuff
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff
  
  
  > cd things
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff\things
  
  
  > cd frank
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff\things\frank
  
  
  > cd joe
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff\things\frank\joe
  
  
  > cd alex
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff\things\frank\joe\alex
  
  
  > cd john
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff\things\frank\joe\alex\john
  
  
  > cd ..
  > cd ..
  > cd ..
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff\things\frank
  
  
  > cd ../..
  > pwd
  
  Path
  ----
  C:\Users\zed\temp\stuff
  
  
  > cd ..
  > cd ..
  > cd temp/stuff/things/frank/joe/alex/john
  > cd ../../../../../../../
  > pwd
  
  Path
  ----
  C:\Users\zed
  
  
  >

5.2 You Learned This

You made all these directories in the last exercise, and now you're just moving around inside them with the cd command. In my session above I also use pwd to check where I am, so remember not to type the output that pwd prints. For example, on line 3 you see ~/temp but that's the output of pwd from the prompt above it. Do not type this in.

You should also see how I use the .. to move "up" in the tree and path.

5.3 Do More

A very important part of learning to the use command line interface (CLI) on a computer with a graphical user interface (GUI) is figuring out how they work together. When I started using computers there was no "GUI" and you did everything with the DOS prompt (the CLI). Later, when computers became powerful enough that everyone could have graphics, it was simple for me to match CLI directories with GUI windows and folders.

Most people today, however, have no comprehension of the CLI, paths, and directories. In fact, it's very difficult to teach it to them and the only way to learn about the connection is for you to constantly work with the CLI until one day it clicks that things you do in the GUI will show up in the CLI.

The way you do this is by spending some time finding directories with your GUI file browser, and then going to them with your CLI. This is what you'll do next.

  1. cd to the joe directory with one command.
  2. cd back to temp with one command, but not further above that.
  3. Find out how to cd to your "home directory" with one command.
  4. cd to your Documents directory, then find it with your GUI file browser (Finder, Windows Explorer, etc.).
  5. cd to your Downloads directory, then find it with your file browser.
  6. Find another directory with your file browser, then cd to it.
  7. Remember when you put quotes around a directory with spaces in it? You can do that with any command. For example, if you have a directory I Have Fun, then you can do: cd "I Have Fun"


Online Video Course + PDF For $9

For the price of most other course's PDFs only, you can get the full PDF for this class and 2 videos demonstrating the whole book for both Unix/OSX Terminal and Windows PowerShell. The course is self-paced so you can go through it any time you want, as many times as you want.


Signup Now At Udemy.com For $9