What's actually in the file
Bytes, the extension is a hint, one ls -la line, editor vs browser.
You will be able to
- Rename a copy of the page from
.txtto.htmland say why the bytes on disk did not change. - Read one
ls -laline forindex.htmland name type, permissions, size, and name. - Open the same
index.htmlin 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.
ls -la line for index.htmlClick each piece.
-d here would mean a directory.rw-r--r--r, w, and x: owner, group, everyone else. You do not need each bit yet..12index.html.html is part of the name.Hidden files. A name that starts with
.is hidden.lsskips 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.
| Text editor | Browser | |
|---|---|---|
| What it shows | The characters, tags and all | The page those characters describe |
| The bytes on disk | Unchanged | Unchanged |
| Its job | Let you read and edit the text | Let you see the page |
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.
The 12 on -rw-r--r--. 1 colin ubuntu 12 Jul 29 04:25 index.html
The file's size, in bytes.
What does ls -a add to a listing?
Names that start with ., which ls otherwise skips.
What does the .html extension actually do?
It is a hint about which app should open the file. It does not change the bytes.
Same index.html, text editor versus browser
The editor shows the characters. The browser draws the page.
Quiz
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).
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).
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).
Sample 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).
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).
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).