Moving around folders in Git & Command Line
Topic 2 of 32 · 8 minFree lessonFolders hold files and other folders, like boxes inside boxes. In the terminal you don't see them on screen, so you move between them with commands. This topic shows you how to get around and how to always know where you are.
Seeing what's here
ls lists what's inside the folder you're in. You'll learn its options in the next topic. For now, it shows you where you can go:
Your home folder has four folders in it: notes, photos, projects and recipes.
Going into a folder
cd means "change directory". Give it the name of a folder, and the terminal moves into it. cd prints nothing when it works, so check with pwd:
Now ls lists the files in notes, because that's where the terminal is.
Going back up
Two dots, .., always mean "the folder above this one", also called the parent folder:
You can go several folders at once by putting names together with / between them. projects/website means "the website folder inside projects":
../.. goes up two folders, one for each ...
Paths
A path says where a file or folder is. There are two kinds:
- A relative path starts from the folder you're in, like
notesor../recipes. - An absolute path starts with
/and goes from the very top of the computer, like/home/learner/recipes. It works the same from anywhere.
The first cd uses an absolute path. The second goes up from recipes and into photos, which sit side by side.
Going home
~ is short for your home folder, and cd with nothing after it takes you there too. cd - jumps back to the folder you were in before, and prints its path:
cd only goes into folders. If you give it a file, or a folder that doesn't exist (often a typo), it says so and stays where it was.pwd tells you where you are, and cd on its own always brings you home.Try it yourself
Run the code in the editor and answer 8 practice questions on moving around folders. It's free, you only need an account.