Navigating the File System
Prerequisites: How the shell runs commands
Files are organized in a tree of directories (folders), starting at
the root, /. Your personal files live in your home directory,
such as /home/ada on Linux or /Users/ada on macOS.
Where am I, and what's here?
mkdir -p projects/website/css projects/notes
cd projects
ls
ls -a
ls website
notes
website
.
..
notes
website
css
cd("change directory") moves you into a folder.ls -aalso shows hidden entries, whose names start with a dot..means "this directory" and..means "the parent directory".ls folderlists another folder without moving.
Absolute and relative paths
- An absolute path starts at the root:
/home/ada/projects/notes. It works from anywhere. - A relative path starts from where you are:
notes,../website.
mkdir -p projects/website/css projects/notes
cd projects/website/css
cd ../..
ls
cd notes && cd ../website && ls
notes
website
css
Shortcuts
| Path | Means |
|---|---|
~ |
your home directory |
. |
the current directory |
.. |
the parent directory |
- |
(with cd) the previous directory |
cd on its own goes home; cd - jumps back to where you were.
Common mistakes
- Spaces in names:
cd My Documentstries to use two arguments. Quote the name —cd "My Documents"— or press Tab to let the shell escape it for you. - Confusing
/(the root) with~(your home).