The Command Line, Enough of It
Moving Around
So far the shell has stayed in one place. cd moves it.
cd data
pwd
/workspace/data
The shell is now standing inside data. Run ls and you will see books.txt and nothing else, not because the rest of the project is gone, but because you are looking at a different directory.
Going back up
There is a name for “the directory above this one”, and it is two dots:
cd ..
pwd
/workspace
.. is not a special command, it is a name you can use in any path, the same way you use a directory’s real name. cd .. means go up one. ls .. means cd ../.. means go up two.
Relative and absolute
Every path you have written so far has been relative: it starts from wherever you happen to be. data/books.txt means “from here, go into data, then take books.txt”. Move somewhere else and the same text points at something else, or at nothing at all.
An absolute path starts from the top of the filesystem and is therefore the same from everywhere. On this machine the top is /, so the
cat /workspace/data/books.txt
You can type that from anywhere and get the same file. The giveaway is the leading /.
Your own machine works the same way as the /, and your files live somewhere under /Users/ and your username.
Run cd / and then ls on your own machine to see the top of the filesystem this course’s paths are measured from.
Windows writes absolute paths differently: they start with a drive letter, like C:\Users\you\projects, and use backslashes between the steps.
PowerShell accepts forward slashes too, so cd data/notes works there as well. The idea is identical: a path from the top of the disk rather than from where you are standing.
Your own machine works the same way as the terminal here. Absolute paths start at /, and your files live somewhere under /home/ and your username.
Run cd / and then ls on your own machine to see the top of the filesystem this course’s paths are measured from.
Both kinds are useful and neither is more correct.
Computer Fundamentals walks the same ground with more examples, including the ~ shortcut for your home directory, and drive letters on Windows:
Why this is the thing that trips people up
Almost every “it works for you but not for me” problem a beginner hits with the terminal is a working directory problem. The file is there. The command is right. The shell is standing somewhere else.
pwd and ls, in that order, answer it nearly every time.
You are in /workspace and cat data/books.txt works. You then run cd data. What happens if you run cat data/books.txt again?
Next: making something of your own, from the terminal.