cd changes the current directory, and with it the meaning of every relative path. Three short commands take you up, home, and back.
cd path moves the shell into a directory and prints nothing. pwd and the prompt show where you ended up.
| Command | Where it takes you |
|---|---|
cd .. |
to the parent directory, one level up |
cd |
home, to ~ |
cd - |
back to the directory you were in before the last cd |
Two dots .. name the parent directory, and a single dot . is the current directory itself. They can sit inside a path: from /etc/nginx/sites-available, the path ../nginx.conf leads to /etc/nginx/nginx.conf.
You can only move into a directory. Given a file, cd prints the error Not a directory.
Up, across, and back
You are in ~/path-lab/project. Run the three commands: a move through .., pwd, and a return with cd -.
First, predict
You are in ~/path-lab/project. Where does cd ../notes take you?
Now start the exercise, run the command and compare your prediction with the output.