The address of a file
Absolute vs relative, ~ . .., and why Index.html is a trap.
You will be able to
- Tell absolute from relative by the first character, and write this file's absolute path starting from
/. - Write the same location three ways with
~,., and... - Predict whether
Index.htmlandindex.htmlare the same file on a default Mac and on Linux.
Look at the address bar. The page is already open.
Copy what you see. On Linux it should be:
file:///home/you/projects/first-site/index.html
That string is this file’s address. An address is the written location of one file.
The bar shows three slashes because file:// sits against a path that starts with /. You will write that path three ways before you leave this page.
The first character
A path is the address of a file or a folder on the machine.
Look at the part after file://. It begins with /.
Click any piece of the string.
file:///homeyou~ is a short name for this same folder.projectsfirst-siteindex.htmlfile://, the rest is the file's absolute path. It starts at /.An absolute path starts with /. It is a route from the top of the machine. That top is root — the folder that contains every other folder.
If the first character is not /, the path is relative. A relative path starts from where you are standing.
/home/you/projects/first-site | projects/first-site | |
|---|---|---|
| First character | / — so absolute | p — so relative |
| Starts from | the top of the machine | where you are standing |
| Always this folder? | yes | only if you are already in /home/you |
/home/you/projects/first-site always names this folder. projects/first-site names a projects folder under wherever you are now.
Write the file’s absolute path:
/home/you/projects/first-site/index.html
That is the same place the browser already showed you. file:// is how the browser opened it. The path after those slashes is the address on disk.
Drop the first / and you get home/you/projects/first-site/index.html. That looks complete. It is not. It starts with h, so it is relative. It only names this file if you are already standing at root.
Three short names
You will not type the full path every time. Three marks stand in for pieces of it.
~ is home. Home is this account’s folder. On Linux that folder is /home/you. So the same file is:
~/projects/first-site/index.html
The shell is the program that reads what you type. It replaces ~ with home first. The result starts with /. Bare cd, with no folder after it, goes home too.
Look at the address bar again. Strip file://. Cover /home/you with your thumb. What remains is /projects/first-site/index.html. Put ~ in front of that remainder. You have just written the home form.
. is here. It names the folder you are standing in. From inside first-site, the page is:
./index.html
You do not name projects or home in that spelling. You are already inside the folder that holds the file, so the file’s name is enough. The . makes that starting point explicit.
.. is the folder above. From inside first-site, .. is projects. cd means change folder. From inside first-site, cd .. puts you in projects.
You can stack the mark. ../.. is two folders up.
From one folder above first-site, the same file is ../first-site/index.html. From two folders above, it is ../../projects/first-site/index.html. Same file. Different starting points.
The first-character rule still holds. ./index.html starts with ., so it is relative. ../first-site/index.html starts with . too. ~/projects/first-site starts with ~. The shell expands ~ to home, and that result is absolute.
A space will split a name
If a folder name has a space, an unquoted command treats it as two names. Keep this folder as first-site. If you must use a space, put quotes around the whole path.
Case is a trap
On Linux, Index.html and index.html are two files. Both can sit in one folder, with different contents.
Your page is index.html. Ask for Index.html and Linux looks for a different name. The letters look similar to you. To the machine they do not match.
On a Mac. APFS is the Mac filesystem. A filesystem is how the machine stores names and files. The default is case-insensitive:
Index.htmlandindex.htmlare the same file. It is also case-preserving: it remembers the capitals you typed, but a change of case does not make a new file. A site that works on a Mac asIndex.htmlcan 404 on Linux over that one letter. A 404 means the name was not found.
On Windows / WSL. The Linux filesystem is case-sensitive, like Linux. The Windows drive at
/mnt/cis not. Keep the project in the Linux home, and type the name exactly.
Three ways, one file
Write the address now:
- from the top:
/home/you/projects/first-site/index.html - from home:
~/projects/first-site/index.html - from inside the folder:
./index.html
The first character tells you which kind you wrote. / is from the top. ~ is from home. . is from here.
Keep the letters exact. The name is index.html, not Index.html.
You know where the file lives. Next you look at what is inside it.
Flashcards
How do you tell an absolute path from a relative one?
Look at the first character. / means absolute. Anything else is relative.
What does ~ stand for in a path?
Your home folder. On Linux that is /home/you.
What does . mean in a path?
The folder you are standing in. From inside first-site, this page is ./index.html.
What does .. mean in a path?
The folder above the one you are standing in.
Default Mac filesystem: does case matter in a filename?
Not for identity. APFS is case-insensitive by default, and case-preserving — it remembers the capitals you typed.
Quiz
Show answer
Answer: False
The opposite is true. Default APFS is case-insensitive, so those two names are the same file. It is case-preserving: it remembers the capitals you typed, but a change of case does not create a second file. Linux is the one that treats them as two files (objective 6).
The opposite is true. Default APFS is case-insensitive, so those two names are the same file. It is case-preserving: it remembers the capitals you typed, but a change of case does not create a second file. Linux is the one that treats them as two files (objective 6).
Show answer
Answer:
/home/you/projects/first-site/index.html
A full-credit answer shows: A strong answer covers the expansion of ~ to /home/you, keeps /projects/first-site/index.html after that, starts with /, and uses lowercase index.html.
~ is home. Home here is /home/you, so the shell rewrites the path as /home/you/projects/first-site/index.html. The rest of the path is unchanged. The result starts with /, so it is absolute (objective 5).
Sample answer
/home/you/projects/first-site/index.html
A full-credit answer shows
A strong answer covers the expansion of ~ to /home/you, keeps /projects/first-site/index.html after that, starts with /, and uses lowercase index.html.
~ is home. Home here is /home/you, so the shell rewrites the path as /home/you/projects/first-site/index.html. The rest of the path is unchanged. The result starts with /, so it is absolute (objective 5).
Show answer
Answer: Relative, because it does not start with /
The first character is p, not /, so the path is relative. Naming several real folders does not make a path absolute — /home/ and home/ are different kinds, and only the leading slash decides. ~ is a shortcut for home, not the test for relative. A filename at the end is just the last piece of the address (objective 4).
The first character is p, not /, so the path is relative. Naming several real folders does not make a path absolute — /home/ and home/ are different kinds, and only the leading slash decides. ~ is a shortcut for home, not the test for relative. A filename at the end is just the last piece of the address (objective 4).