The address of a file

Absolute vs relative, ~ . .., and why Index.html is a trap.

You will be able to

  1. Tell absolute from relative by the first character, and write this file's absolute path starting from /.
  2. Write the same location three ways with ~, ., and ...
  3. Predict whether Index.html and index.html are 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 /.

AnatomyThe address already in your bar

Click any piece of the string.

////
how it openedfile://
The browser opened a file on this machine, not a page on the internet.
root/
The top of the machine. Every absolute path starts here.
accountshome
Where Linux keeps each account's folder.
this accountyou
Your home. ~ is a short name for this same folder.
projects folderprojects
The folder that holds this site.
this sitefirst-site
The folder that holds the page.
the fileindex.html
The page itself. Spell every letter exactly.
After file://, 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.

CompareSame folders, two kinds of address
/home/you/projects/first-siteprojects/first-site
First character/ — so absolutep — so relative
Starts fromthe top of the machinewhere you are standing
Always this folder?yesonly if you are already in /home/you
The first character decides the kind. The rest of the words can look the same.

/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.html and index.html are 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 as Index.html can 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/c is not. Keep the project in the Linux home, and type the name exactly.

Three ways, one file

Write the address now:

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.

1 / 5

Quiz

Question 1 of 3

On a default Mac, Index.html and index.html are two different files.

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).

Question 2 of 3

Your home is /home/you. Write the absolute path of ~/projects/first-site/index.html.

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).

Question 3 of 3

You type projects/first-site/index.html. Is this path absolute or relative, and why?

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).

Erase saved progress?

This erases all quiz scores, reading progress, project checklists, and your name on the certificate. It cannot be undone, and it affects only this course in this browser.