The Anatomy of a File System, Explained

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 6.2 Free with a free account

The Anatomy of a File System

Introduction to Operating Systems · Chapter 6: File Systems and Data ManagementSection 6.2 · lesson 49 of 837 min · free with a free account

← The Storage Beneath File SystemsNext lesson: File Managers →

A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

In this lesson

How directories, metadata and inodes let a file system find files.

  • Describe the directory tree and write absolute and relative paths
  • Explain what an inode stores and why the file name lives in the directory
  • Count the name lookups needed to open a file from its path
  • Explain why renaming is instant and why deleted files can sometimes be recovered

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (941 words). Read along, or search it.

Opening Puzzle

A Four Gigabyte Rename in No Time

Imagine a library with a million books and no catalog. You could still find a book, but only by walking every aisle. A file system is the catalog. It keeps a card for every file, and a set of shelves, the folders, that gives each card a place. Now a puzzle to keep in mind. Sam, who runs a small online bakery, renamed a 4 GB folder of cake photos, and it took no time at all. Four gigabytes, and nothing to wait for. By the end of this lesson, you'll know why.

Directory Tree

Folders Grow From a Single Root

Start with the shelves. Ivy, who looks after the computers at a school, keeps a copy of Sam's shop files on her Linux server. A directory, or folder, is a file whose contents are a list of other names. Some of those names are plain files, and some are more directories. So the shape is a tree: one starting point, the root, with branches that split. Every item has exactly one parent: the directory that lists it. Only the root at the top has none.

Paths

Absolute and Relative Paths

A path names one item by spelling out the route to it from the root: slash home, slash sam, slash shop, slash recipes, slash muffins dot t x t. A relative path starts where you're standing instead. From shop, orders slash twenty twenty-six goes two steps down, and dot dot climbs one step up.

Metadata

Facts About a File, Not the File

Now the cards. Metadata is data about data. A library card holds the title, the author and the shelf, but none of it is the book itself. A file system keeps similar facts for every file: its type, its size in bytes, its permissions, its owner, its times, and how many names point to it. Take muffins dot t x t. It holds flour, sugar, eggs: eighteen characters. Yet its size is nineteen bytes, because the line ends with an invisible newline character. And size isn't space used. Those nineteen bytes still reserve a whole block on the drive, as you saw in lesson six point one.

Inodes

The Inode Holds Everything but the Name

On Unix and Linux file systems, that card is called an inode, short for index node. The inode holds the metadata, and the list of blocks where the contents live. Lesson six point four looks at that list. Here's the surprising part: the inode does not hold the file's name. The name lives in the directory. A directory is just a table of pairs: a name, and an inode number.

Consequences

Names, Renames and Link Counts

That explains three things. One file can have several names, each a row in some directory. Lesson six point six shows these links. Renaming a file, even a huge one, only changes a row in one table. The data never moves. And the inode's link count is simply how many directory rows point to it.

Quick Check

Which Move Takes Real Time

Quick check. Ivy has a four gigabyte video on her server's drive, and tries three things with it. Rename it in the same folder. Move it into another folder on the same partition. Or move it onto a USB stick. Which one takes real time? Pause, and decide. The USB stick. It's a different file system, with its own records and its own blocks, so every byte has to be copied across. Moving to another folder on the same partition is as quick as renaming. The old directory loses a row, and the new one gains it. The inode and the data stay put.

Path Lookup

Walking a Path One Name at a Time

How does the operating system find a file from its path? Say it opens slash home, slash sam, slash shop, slash recipes, slash muffins dot t x t. It starts at the root directory, which sits at a known place on the partition, and it repeats one move. Look up the next name in the current directory, take its inode number, and load that inode. Then do it again. Home, sam, shop, recipes, and finally muffins dot t x t: five lookups, one per name.

Quick Check

Counting Lookups to a File

Quick check. Ivy opens a file at slash home, slash ivy, slash lab, slash notes dot t x t. Starting from the root, how many name lookups does it take to reach the file's inode: three, four, or five? Pause, and decide. Four. Home, ivy, lab, and notes dot t x t: one lookup for each name after the root. The root itself needs no lookup, because the system already knows where it is. That's why it isn't five. Four lookups, then, and no more.

Deleting Files

Removing a Name, Not the Bytes

Now deleting makes sense. When you remove a file, the OS removes its name from the directory, and lowers the inode's link count by one. If the count reaches zero, and no program has the file open, the inode and its blocks are marked free, ready to be reused. Nothing is wiped on the spot. The old bytes stay until new data lands on top. That's why a deleted file can sometimes be recovered, and why you can't count on it. For real secrets, use a tool made for secure erasing.

Puzzle Solved

Why the Big Rename Was Instant

Back to Sam's four gigabyte folder. The rename changed one name, in one row of one directory. Windows calls its cards file records rather than inodes, but the idea is the same. Every block of every photo stayed exactly where it was, so there was nothing to wait for.

Key Takeaways

Directories, Inodes and Lookups

To recap. A directory is a list of names, and directories form a tree that grows from the root. The facts about a file, its metadata, live in its inode. The name doesn't. A directory row pairs a name with an inode number, and the link count counts those rows. Opening a path takes one lookup per name, and deleting removes a row.

About Introduction to Operating Systems at UPI Study

Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About The Anatomy of a File System

What is an inode in Linux?
An inode, short for index node, is the record a Unix or Linux file system keeps for each file. It holds the file's metadata, such as type, size, permissions, owner, times and link count, plus the list of blocks where the contents live. It does not hold the file's name. Names live in directories, which pair each name with an inode number.
How do absolute and relative paths walk the folder tree?
An absolute path names a file by its full route from the root, while a relative path starts from the current folder. For example, /home/sam/shop/recipes/muffins.txt works from anywhere. From inside the shop folder, the relative path orders/2026 goes two steps down, and two dots climb one level up to the parent folder.
Why is renaming a large file instant?
Renaming is instant because it changes one row in a directory table, not the file's data. A directory pairs each name with an inode number, and the inode points to the data blocks. Changing the name leaves the inode and every block where they are, so a four gigabyte file renames as fast as a tiny one. Moving a file within the same partition works the same way.
Can a deleted file be recovered?
Sometimes, because deleting removes the file's name from its directory and, once no other name or open program uses the file, marks its inode and blocks as free without wiping the bytes. The old data stays until new data is written over it, so recovery tools can occasionally bring it back. That makes recovery unreliable, and it also means anyone who needs to destroy sensitive data should use a tool built for secure erasing.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Introduction to Operating Systems.

83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Introduction to Operating Systems
3 credits · NCCRS
Enroll →