The shell stands somewhere

pwd, ls, cd — the same command, two folders, two listings.

You will be able to

  1. Print where the shell is standing with pwd and say why the same ls prints different things in different folders.
  2. Move with cd ~/projects/first-site and cd .., then confirm with pwd.
  3. Jump home with bare cd and back with cd -, and read your location from the prompt.

Open a terminal. Type pwd and press Enter.

One line comes back. It is an absolute path — the folder the shell is standing in right now.

The shell is the program that reads what you type and runs it. It always stands in exactly one folder. That folder is the current working directory. Every name without a leading / is measured from there. Until you ask, you do not know where you stand. That is why pwd exists.

Your page already lives at ~/projects/first-site/index.html. The shell is probably not in that folder yet.

Type this and press Enter:

cd ~/projects/first-site

If the path feels long, press Tab after a few letters. The shell finishes a unique name.

Now type pwd again. On Linux it prints /home/you/projects/first-site.

The shell moves. The file does not.

pwd means print working directory. It names the folder. It changes nothing.

cd means change directory. It is a shell builtin: a command the shell itself performs, not a separate program. It moves the shell. It does not move the file.

An absolute path begins with /. pwd always prints one, so you can read it from anywhere.

~ is a short name for your home folder. ~/projects/first-site starts from home, so cd can find it no matter where you stood.

A relative path does not begin with /. index.html is relative. So is first-site. Each is a name measured from the folder you stand in.

Walk it once and predict each line before you reveal it.

Try itStand in the project, then step up
cd ~/projects/first-site
pwd
/home/you/projects/first-site
An absolute path. Relative names you type next are measured from here.
cd ..
pwd
/home/you/projects
.. is the parent. One level up. index.html lives one level down.
pwd names the folder. cd moves the shell. The file stays put.

Same command, new folder

Stand in the project again if you have moved:

cd ~/projects/first-site

Confirm with pwd. Then type ls. With no extra words, ls lists the current directory. Your index.html is one of the names here.

Now type cd .. and press Enter. .. means the parent folder — one level up.

Type ls again. Same command. Different names. The command did not change. The vantage point did.

That is the whole idea. ls does not search the machine. It reports the folder you stand in. Change folder and you change the report. If you expected index.html in the second listing and it is gone, you moved. The file did not.

CompareSame ls, two standpoints
In first-siteIn projects
What ls liststhis folderthis folder — different names
index.htmlherenot in this folder
A command that names index.htmlfinds the fileNo such file or directory
The command did not change. The folder you stand in did.

Type pwd. You are in /home/you/projects. index.html is not here. It is still inside first-site.

This is why a good path can still fail. Stand in the wrong folder and type a relative name. The shell replies No such file or directory. The file is fine. You are standing somewhere else.

People often read that message as a broken file. It is a lookup that found nothing. The bytes on disk did not change when you typed cd ... Only your vantage point did.

Run pwd before you decide the file is gone. If the path is not the folder you meant, move with cd and try the name again.

Home, back, and the prompt

Look at the prompt — the text the shell prints before your cursor. On Linux it ends $. That $ is not part of the command. Do not type it.

On a Mac. The default shell is zsh, and the prompt ends %. Do not type the %. After the same cd, pwd prints /Users/you/projects/first-site.

The prompt often shows a short form of your folder before that mark. After cd, that text changes. Read your location from it as a glance. Use pwd when you want the full path.

Type cd with nothing after it. Bare cd goes to $HOME — your home folder. On Linux, pwd now prints /home/you. Look at the prompt: it should now show ~.

Type cd -. This toggles. It returns you to the last folder and prints that path. After the step above, that path is /home/you/projects. The prompt updates to match.

cd - is the one cd that talks. The others stay quiet and leave the prompt to show the move. Run it twice and you swap back again.

Get back to the project from anywhere:

cd ~/projects/first-site

Confirm with pwd. Stay there.

The mouse is not required. You can stand in this folder from any starting point. Next you will rebuild it from the keyboard.

Flashcards

Which command prints where the shell is standing?

pwd — print working directory. One absolute path. It changes nothing.

1 / 5

Quiz

Question 1 of 3

When the shell prints No such file or directory, the file on disk is corrupted.

Show answer

Answer: False

The message means a lookup found nothing from where you are standing. A relative name is measured from the current folder, so the same file is missing from one vantage point and present from another. Run pwd before you decide the file is damaged. (objective 1)

Question 2 of 3

You have wandered off. How do you stand in the project folder from anywhere, and how do you prove it?

Show answer

Answer:

Type cd ~/projects/first-site, then pwd. The printed path ends in /projects/first-site.

A full-credit answer shows: A strong answer covers the cd to ~/projects/first-site (an absolute /home/you/… form is also fine) and a pwd check whose path ends in /projects/first-site. Mentioning the prompt as a glance is extra, not a substitute for pwd.

cd ~/projects/first-site works from any starting folder because it starts from home, not from where you stand. pwd is the proof: it prints the absolute path and changes nothing. The prompt may already show the folder, but pwd is the command whose job is to name it. (objective 2)

Question 3 of 3

You run these commands in order:

cd ~/projects/first-site
cd ..
pwd

What does the last command print on Linux?

Show answer

Answer: /home/you/projects

cd ~/projects/first-site lands in the project folder. cd .. then stands in the parent, so pwd prints /home/you/projects. The first option is where you were before ... The third treats .. as going home — that is bare cd, not cd ... The fourth uses ~, but pwd always prints an absolute path beginning with /. (objectives 1, 2)

Erase saved progress?

This erases all quiz scores, reading progress, project checklists, and your name on the certificate. It cannot be undone, and it affects only this course in this browser.