PythonIntermediate PythonNumPySQLGen AI
HTMLCSSJavaScriptIntermediate JavaScriptReactp5.jsNode.js
Command LineGit & GitHub
C++JavaData Structures & Algorithms

Exercise

03 |

Change Directory: cd

So we can open the command line as well as view the current directory in our computer's filesystem.

But how do we actually navigate the filesystem via the command line? We do this with the cd “change directory” command!

$ cd directory-name

The directory-name is the directory we want to change into (making this the new current directory).

Let's say we're currently on the following working directory:

$ pwd
/Users/dwight-schrute/

Your username is also a directory that contains more directories, including one for your computer's desktop! We can move to that Desktop directory with the cd command:

$ cd Desktop
$ pwd
/Users/dwight-schrute/Desktop

If you try to change into a non-existent directory, you'll get an error:

$ cd something
something: No such file or directory

List Content: ls

But wait, how do you always know what you're typing next to cd is a valid directory name? There's a command to list out all subdirectories under our current directory!

We can use the ls list command to show all directories and files that exist in your current working directory. Assuming we're on the dwight-schrute directory:

$ ls
Desktop
Documents
Images
script.js
dundie-awards.txt 

Running the ls command shows there are three subdirectories:

  • Desktop
  • Documents
  • Images

There are also two files, script.js and dundie-awards.txt.

Instructions

For the duration of this chapter, we will be exploring a house directory, which you can download here:

house.zip

Note: Clicking this may save this to your computer's Downloads folder.

Go ahead and move this folder to your desktop and unzip it. Next, change into the house directory with the cd command.

Then, view all the directories and files underneath. You should see the following:

bedroom    kitchen    bathroom    dining-room    living-room

You will need this for the next exercise!

Help

Get a Hint

Want the solution? Try completing the lesson first!

New Item Unlocked!

pom pom characters gifitem duck

Rubber Duck NEW

Rubber duck debugging is a classic technique used by developers to debug code. By explaining the code line-by-line to a rubber duck, you can break down the code into smaller pieces, and potentially identify the error.

... It's silly, we know.

New Item Unlocked!

pom pom characters gifitem duck

Codédex BotNEW

I’m a coding mentor bot built with GPT-4 👋. I’m here to answer any questions related to programming, Codédex, and much more.

FEATURE UNLOCKED!

sad characters gif

You have 100 XP! This means you can now join our Discord community to chat and hang out with fellow learners and the team behind Codédex!
See you there. 😊

FEATURE UNLOCKED!

pom pom characters gif

You have 250 XP! This means you can now join our On-Platform community to chat and hang out with fellow learners!
Say hi in the Introductions channel. 😊

Navigation

01. Beginning...

02. Filesystem

03. Moving Day

04. House Tour

05. Clean Slate

06. Scavenger Hunt

Manipulation

03. Moving Day

10 XP