What's actually in the file

Bytes, the extension is a hint, one ls -la line, editor vs browser.

You will be able to

  1. Rename a copy of the page from .txt to .html and say why the bytes on disk did not change.
  2. Read one ls -la line for index.html and name type, permissions, size, and name.
  3. Open the same index.html in a text editor and a browser, and say what each does with the identical bytes.

Open the folder that holds your page. That is ~/projects/first-site. You already know how to write that address.

Find index.html. Make a copy of it in the same folder. Name the copy notes.txt.

Open notes.txt in a text editor. A text editor is a program that shows a file as characters. You should see the same heading as index.html.

Now rename notes.txt to notes.html. Watch the icon. Watch which app wants to open it.

Open notes.html in the editor again. The heading is still there. The name changed. The text did not.

The suffix after the last dot is the extension. It is a hint about which app should open the file. It does not convert the file.

People often treat a rename as a conversion. It is not. The bytes — the actual contents on disk — stay put. You now have two names in the same folder. Open both in the editor if you want proof. The heading matches.

On a Mac / On Windows. Your file manager can copy and rename too. The bytes still do not change.

Read one line

You have two files now: index.html and notes.html. Look at them the way the machine does.

Type this:

ls -la ~/projects/first-site

ls lists files. With no path it lists the current directory. The path here means you do not have to move first.

-l asks for a long listing — one row per file, with extra fields. -a means do not skip names that start with .. Together they print every name, with type, size, and the rest on one line.

Your listing will not match the one below. The owner, the date, and the size will be yours. The fields sit in the same places. Here is a captured index.html line, with the folder’s own line above it:

drwxr-xr-x.   3 colin ubuntu  120 Jul 29 04:25 .
-rw-r--r--.   1 colin ubuntu   12 Jul 29 04:25 index.html

Read left to right. The first character is the type. - means a regular file. d means a directory. The . line is the folder itself, so it starts with d. Your index.html line should start with -.

Next come three groups of r, w, and x. Those are permissions for the owner, the group, and everyone else. You do not need each bit yet. Just see that the three groups are there.

Skip the small integers and the two names that follow. The number 12 on the captured index.html line is the size, in bytes. On the folder line the size is 120. That is the folder’s own row, not the file. The last field is the name.

Find those four things on your own index.html line: type, permissions, size, name. The numbers will differ. The order will not.

An extra character may sit after the permission groups. This captured line has a trailing .. That mark is an SELinux security-context marker. Plain Ubuntu prints ten characters and no extra dot. Either way, start reading at the type character.

AnatomyOne ls -la line for index.html

Click each piece.

1 colin ubuntu Jul 29 04:25
type-
A regular file. A d here would mean a directory.
permissionsrw-r--r--
Three groups of r, w, and x: owner, group, everyone else. You do not need each bit yet.
extra mark.
An SELinux marker. Plain Ubuntu prints ten characters and stops.
size12
The file is 12 bytes on this captured line. Yours will be a different number in the same slot.
nameindex.html
The last field. The .html is part of the name.
Type, permissions, size, name. The rest can wait.

Hidden files. A name that starts with . is hidden. ls skips it unless you pass -a, so a folder can look empty.

Same bytes, two readings

Leave the listing. Open index.html in the text editor. You see the characters, tags and all.

Open the same index.html in the browser. You see the page those characters describe.

You did not make a second file. The bytes on disk are identical. Each program reads them for a different job.

Compare
Text editorBrowser
What it showsThe characters, tags and allThe page those characters describe
The bytes on diskUnchangedUnchanged
Its jobLet you read and edit the textLet you see the page
One file. Two programs. Two readings.

The editor is for the text. The browser is for the page. Neither one rewrites the file just because you opened it.

Try it with notes.html as well. The editor still shows the same heading. The browser still draws that heading as a page. The rename only changed the name.

What you carry forward

This file is bytes with a name. The extension is a hint, not a conversion. You can now read one ls -la line for this index.html, and you have opened the same bytes in an editor and a browser.

Next, Unit 2 rebuilds this same page from the keyboard. No mouse. Same folder. Same file.

Flashcards

- versus d at the start of an ls -la line

- is a regular file. d is a directory.

1 / 5

Quiz

Question 1 of 3

Renaming notes.txt to notes.html converts the file into HTML.

Show answer

Answer: False

The opposite is true. A rename changes only the name. The bytes on disk stay put, which is why the heading is still there when you open notes.html in the editor. The .html extension is a hint about which app should open the file, not a conversion (objective 7).

Question 2 of 3

Read this captured line and name the type, the permissions field, the size, and the name.

-rw-r--r--. 1 colin ubuntu 12 Jul 29 04:25 index.html

Show answer

Answer:

Type is a regular file (-). Permissions are rw-r--r--. Size is 12 bytes. Name is index.html.

A full-credit answer shows: A strong answer covers all four fields: type as a file (or -), the rw-r--r-- permissions, size 12, and the name index.html.

Left to right: - is the type (a regular file), rw-r--r-- is the three permission groups, 12 is the size in bytes, and index.html is the name. The tempting misses are calling 1 the size, or reading d from the folder line above it (objective 8).

Question 3 of 3

You open the same index.html in a text editor and in a browser. What is true?

Show answer

Answer: Same bytes: editor shows the text, browser draws the page

It is one file. The editor shows the characters; the browser draws the page those characters describe. The browser does not convert the file first — the bytes are already the page. You did not make a second copy, and opening the file does not rewrite it (objective 9).

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.