Code / Command Line & Git / Unit 1: The terminal: finding your way

Moving around folders फ़ोल्डरों में घूमना

Lesson 2 of 12 · about 14 minutes · cd, cd .., ~, absolute and relative paths, Tab and history.

⚡ 0 XP

Step 1 of 3

cd: walk into a folder

~$ mkdir shop~$ cd shop~/shop$ ls

Folders sit inside folders, like rooms inside a house. cd (change directory) walks you into one: cd shop.

Watch the prompt change from ~ to ~/shop. That is your current location.

Tab completion: type the first letters, like cd sh, then press Tab. The terminal finishes the name for you. It saves typing and avoids spelling mistakes, so use it all the time (it works here too).

Example
ls
cd shop
pwd
ls

🎯 Challenge: Walk into the kitchen +10 XP

Your stall has a folder shop with rooms inside. Go into shop, run ls to look around, then go into kitchen. You must end inside ~/shop/kitchen.

Try twice to unlock the solution (0/2)

terminalCtrl ⏎

A safe practice terminal. Type a command and press Enter. Type help to list commands. Tab completes names, ↑ recalls the last command.

Files · ~ = /home/asha
  • shop/
  • counter/
  • cash-book.txt
  • kitchen/
  • fridge/
Git timeline

No git repository yet. Start with git init.

Checklist

Press Run to check your code.

  • You are inside ~/shop/kitchen
  • You looked around with ls
  • You used cd
Lesson notes (text version)

1. cd: walk into a folder

Folders sit inside folders, like rooms inside a house. cd (change directory) walks you into one: cd shop.

Watch the prompt change from ~ to ~/shop. That is your current location.

Tab completion: type the first letters, like cd sh, then press Tab. The terminal finishes the name for you. It saves typing and avoids spelling mistakes, so use it all the time (it works here too).

                ls
cd shop
pwd
ls
              

Challenge: Walk into the kitchen

Your stall has a folder shop with rooms inside. Go into shop, run ls to look around, then go into kitchen. You must end inside ~/shop/kitchen.

2. cd .. : one step up

Two dots .. always mean "the folder above me". So cd .. climbs one level up, and cd ../.. climbs two levels in one go.

And cd ~ (or just cd) takes you straight home from anywhere. Lost? pwd tells you where you are.

                pwd
cd ..
pwd
cd ~
pwd
              

Challenge: Back from maths class

You start deep inside ~/school/class9/maths. Climb up with cd .. until you are in ~/school, then run pwd to confirm.

3. Absolute vs relative paths

A path is an address for a file or folder.

  • A relative path starts from where you are now: cd kitchen, cd ../counter.
  • An absolute path starts from the top, /, so it works from anywhere: cd /home/asha/shop.
  • ~ is a shortcut for your home, so ~/shop is the same as /home/asha/shop.

Think of a relative path as "two shops to the left" and an absolute path as a full postal address with PIN code.

History: history lists the commands you typed. In most terminals (and here) the ↑ arrow brings back your last command, so you never retype long lines.

                cd /home/asha/shop
pwd
cd ~
pwd
history
              

Challenge: Teleport from Goa to Manali

You are on the beach in ~/trips/goa/beach. Jump straight to ~/trips/manali/snow with one cd using a full path that starts with ~/ or /. Then run history to see what you typed.

Search by task, format or tool name.