Files and File Systems
Table of Contents
- What Is a File?
- The File System
- Folders and the Tree
- Paths: A File's Address
- File Extensions
- Hidden Files
- Permissions
- Deleting Isn't Always Deleting
- Try It Yourself
1. What Is a File?
Storage, at the lowest level, is just a gigantic sequence of bytes — hundreds of billions of them on a typical SSD. Nobody could work with that directly. "Put my essay at byte 83,402,112" is not a useful way to think.
A file is the solution: a named chunk of bytes. essay.docx,
photo.jpg, and app.js are all just sequences of bytes with a name
attached, plus some extra information about them:
- Size — how many bytes it contains
- Timestamps — when it was created and last modified
- Owner and permissions — who is allowed to read or change it
As you saw in chapter 2, the bytes inside can mean anything — text, pixels, sound, or machine code. The file itself doesn't care.
2. The File System
Something has to keep track of which bytes on the disk belong to which file, what each file is called, and which parts of the disk are free. That job belongs to the file system, which is managed by the operating system.
You can think of it as the library catalogue for your disk: it doesn't contain the books themselves, but it tells you exactly which shelf each one is on.
Different operating systems use different file systems:
| File system | Used by |
|---|---|
| NTFS | Windows |
| APFS | macOS and iOS |
| ext4 | Most Linux systems |
| FAT32 / exFAT | USB drives and SD cards, because every OS can read them |
This is why a USB drive formatted on a Mac sometimes can't be written to on Windows, and why "formatting" a drive erases it — formatting means creating a brand new, empty file system on it.
3. Folders and the Tree
A folder (also called a directory) is a container that holds files and other folders. Because folders can hold folders, the whole file system forms a tree:
/
├── Users
│ └── dara
│ ├── Documents
│ │ └── essay.docx
│ ├── Pictures
│ │ └── angkor.jpg
│ └── projects
│ └── my-app
│ ├── package.json
│ └── src
│ └── index.js
└── Applications
At the very top is the root. On macOS and Linux the root is written
as /. On Windows, each drive has its own root, like C:\.
4. Paths: A File's Address
A path is the address of a file — the list of folders you pass through to reach it, from the root down.
On macOS and Linux, folders are separated by forward slashes:
/Users/dara/Pictures/angkor.jpg
On Windows, by backslashes, starting from a drive letter:
C:\Users\dara\Pictures\angkor.jpg
There are two kinds of path:
- An absolute path starts from the root and works from anywhere —
like a full postal address.
/Users/dara/projects/my-app/src/index.js - A relative path starts from wherever you currently are — like
saying "two doors down". If you're already inside
my-app, the same file is justsrc/index.js.
Two special names appear in relative paths constantly:
.means "the current folder"..means "the folder above this one" (the parent)
So from inside my-app/src, the path ../package.json means "go up
one level, then open package.json". You'll see paths like
./components/Button and ../utils all over real code, and you'll use
them every day in Command Line Basics.
5. File Extensions
The part of the name after the last dot — .jpg, .pdf, .js — is the
file extension. It's a hint to people and to the operating system
about what kind of data is inside, so the OS knows which app should
open it.
Here's the important thing: the extension is just part of the name.
Renaming photo.jpg to photo.txt doesn't change a single byte inside
the file — it's still a JPEG image. It just confuses the OS into opening
it with a text editor, which will show garbage.
This is also a classic trick used by malware: a file called
invoice.pdf.exe might show up as invoice.pdf if the system hides
known extensions, but it's actually a program. Turning on "show file
extensions" is a small, worthwhile safety habit.
Some extensions you'll see a lot as a developer:
| Extension | What it is |
|---|---|
.txt, .md | Plain text, Markdown |
.js, .ts, .py, .go | Source code |
.json, .yaml, .env | Configuration and data |
.html, .css | Web pages and styles |
.exe, .app | Programs (Windows, macOS) |
.zip, .tar.gz | Compressed archives |
6. Hidden Files
Some files are hidden by default so you don't delete them by accident. On macOS and Linux, any file whose name starts with a dot is hidden — which is why these are often called dotfiles.
You'll meet plenty of them in real projects:
.git/— the folder where Git stores your project's history.env— environment variables, often containing secrets.gitignore— the list of files Git should ignore
To show hidden files:
- macOS Finder: press
Cmd + Shift + . - Windows File Explorer: View → Show → Hidden items
- Linux file managers: usually
Ctrl + H
7. Permissions
On a computer with multiple users — or a server running many services — not everyone should be able to read or change every file. The file system stores permissions for each file.
On macOS and Linux, every file has an owner, a group, and three basic permissions for each:
- r — read the file
- w — write (change) the file
- x — execute it (run it as a program), or for a folder, enter it
If you've ever seen the error Permission denied, the OS was enforcing
these rules. It's also why installing some software asks for an
administrator password: system folders are owned by the administrator
(root on Linux and macOS), not by your normal user.
Windows uses a more detailed system called access control lists, but the idea is the same: the OS checks who you are before letting you touch a file. We'll use permissions hands-on in Command Line Basics and Hardening a Linux Server.
8. Deleting Isn't Always Deleting
When you delete a file (and empty the trash), the file system usually just removes the catalogue entry and marks that space as free. The actual bytes often stay on the disk until something new overwrites them.
That's why "undelete" tools can sometimes recover files, and why you should securely erase a drive before selling a computer. On modern SSDs the situation is more complicated — the drive often clears freed space itself in the background — but the lesson holds: deleting a file means the file system forgets it, not necessarily that the data is gone.
9. Try It Yourself
- Open your file manager and find your home folder
(
C:\Users\<you>on Windows,/Users/<you>on macOS,/home/<you>on Linux). - Turn on hidden files using the shortcut above. What dotfiles appear in your home folder?
- Turn on file extensions if they're hidden (on Windows: View → Show → File name extensions).
- Find a photo, and copy its full path (Shift + right-click → Copy as path on Windows; Option + right-click → Copy as Pathname on macOS). Paste it somewhere and read it — that's the file's absolute address.
- Make a copy of that photo and rename the copy from
.jpgto.txt. Open it — you'll see garbage in a text editor. Rename it back and it opens as a photo again. The bytes never changed.
Files and folders are organized by the file system, which is run by the operating system. Next, let's look at the operating system itself.
Buy Me a Coffee
Found this tutorial helpful? Consider buying me a coffee to support more free content!