Files and File Systems

Table of Contents

  1. What Is a File?
  2. The File System
  3. Folders and the Tree
  4. Paths: A File's Address
  5. File Extensions
  6. Hidden Files
  7. Permissions
  8. Deleting Isn't Always Deleting
  9. 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 systemUsed by
NTFSWindows
APFSmacOS and iOS
ext4Most Linux systems
FAT32 / exFATUSB 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 just src/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:

ExtensionWhat it is
.txt, .mdPlain text, Markdown
.js, .ts, .py, .goSource code
.json, .yaml, .envConfiguration and data
.html, .cssWeb pages and styles
.exe, .appPrograms (Windows, macOS)
.zip, .tar.gzCompressed 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

  1. Open your file manager and find your home folder (C:\Users\<you> on Windows, /Users/<you> on macOS, /home/<you> on Linux).
  2. Turn on hidden files using the shortcut above. What dotfiles appear in your home folder?
  3. Turn on file extensions if they're hidden (on Windows: View → Show → File name extensions).
  4. 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.
  5. Make a copy of that photo and rename the copy from .jpg to .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!