The shell stands somewhere
pwd, ls, cd — the same command, two folders, two listings.
You will be able to
- Print where the shell is standing with
pwdand say why the samelsprints different things in different folders. - Move with
cd ~/projects/first-siteandcd .., then confirm withpwd. - Jump home with bare
cdand back withcd -, 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.
cd ~/projects/first-sitepwd/home/you/projects/first-sitecd ..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.
ls, two standpointsIn first-site | In projects | |
|---|---|---|
What ls lists | this folder | this folder — different names |
index.html | here | not in this folder |
A command that names index.html | finds the file | No such file or directory |
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 samecd,pwdprints/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.
What does ls list if you give it no path?
The current directory — the folder the shell is standing in.
What does cd change?
The shell's current folder. It is a builtin. It does not move files.
What is .. when you pass it to cd?
The parent folder. cd .. stands one level up.
What does cd - do?
Toggle to the previous folder and print the path you land in.
Quiz
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)
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)
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)
Sample 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)
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)
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)