The Command Line · practice
Navigate a Project Tree
When a command cannot find a file, the file is usually right where it always was. You are standing somewhere else.
There are three questions worth asking, in this order: where am I, what is here, and where should I go? Every
If you arrived from another course
The /workspace; these are not the files on your own machine. Use that hosted terminal for the graded practice below.
Before starting, you need to report the current directory and resolve a /, ., and .. through a worked directory tree.
What is here
You already know how to ask where you are. Listing what surrounds you is the next question:
Get-ChildItem
ls
ls
A fresh chapter workspace holds this:
/workspace
├── README.md
├── checkpoint/
├── data/
│ ├── README.txt
│ └── measurements.txt
├── destination/
├── environment-check.py
├── notes with spaces.txt
└── report.py
Where should I go
Changing directories takes one command, and the habit worth building is to check afterward rather than assume:
Set-Location -Path ./data
Get-Location
cd data
pwd
cd data
pwd
That destination is a relative path, so it resolved from where you already were. Everything you worked out on paper in the previous chapter applies here unchanged: two dots name the parent, a leading slash starts at the filesystem root, and a tilde stands for your home directory. The shell is simply the first place those rules do something visible.
Climbing back out uses the parent:
Set-Location -Path ..
Get-Location
cd ..
pwd
cd ..
pwd
An /workspace; on your own machine it might be C:\Users\Sam\project or /home/sam/project. Never copy a sample username. Ask where you are and use what the shell tells you.
Leave one piece of evidence
Everything so far only looked. The graded check cannot see where your shell travelled earlier, so you will leave one directory at the destination as evidence that your relative path resolved correctly. The creation command is supplied here; working out the route is the lesson.
New-Item -ItemType Directory -Path ./example-directory
New-Item makes one filesystem item, and -ItemType Directory makes the intended type explicit. It returns a description of what it created; list the parent as a separate check.
mkdir example-directory
mkdir is short for “make directory”. It normally prints nothing when it works, so list the parent as a separate check.
mkdir example-directory
mkdir is short for “make directory”. It normally prints nothing when it works, so list the parent as a separate check.
Creating the directory changes the tree, so use Reset before the practice if you ran the example. Then list the parent after your real command and confirm that the marker landed where you intended.
Practice: leave a marker through a relative path
In the previous chapter you resolved relative paths on paper: write down where you are, take each segment in turn, go up for .., and check where you landed. This is where that stops being an exercise on paper. The shell is standing somewhere specific, and a path you write from the wrong starting point will land somewhere real and wrong.
This one is graded from the workspace. Use Reset first if an earlier attempt left destination/navigation-complete behind.
Confirm you are at
/workspace.List the directory and check that
dataanddestinationare both there.Move into
dataand confirm you arrived.From inside
data, and without using an absolute path, create a directory callednavigation-completeinside the sibling folderdestination. You will need..to climb out ofdatafirst.Return to
/workspaceand listdestinationto confirmnavigation-completeis there.
Step 4 is the whole lesson in one command. You have to know where you are standing before you can write a relative path that lands somewhere else, and the section above showed the command on a throwaway example. Working out the path from data to its sibling is yours.
Leave every supplied file where it is and stay inside /workspace. The check requires the marker directory and verifies key supplied files; use Reset first so unrelated leftovers do not muddy your own listing. Then press Check my work.
You are in /workspace/data and move to ../checkpoint. Where do you end up?
You create a directory, and the command prints nothing. What is the next thing to do?
You can find where you are, see what surrounds you, and move deliberately. Before changing anything, though, you need to know what kind of thing you are pointing at.