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
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:
There are also two files, script.js and dundie-awards.txt.
For the duration of this chapter, we will be exploring a house directory, which you can download here:
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!
Want the solution? Try completing the lesson first!
01. Beginning...
02. Filesystem
03. Moving Day
04. House Tour
05. Clean Slate
06. Scavenger Hunt
03. Moving Day
10 XP