Show understanding of why files are needed

10.3 Files

Files are the building blocks of a computer’s memory. Think of them as digital notebooks that keep information safe even when the computer is turned off. 📁

What is a File?

A file is a named collection of data stored on a storage device. It can contain text, images, programs, or any other type of information.

  • 📄 Text files (e.g., report.txt)
  • 🖼️ Image files (e.g., photo.jpg)
  • 🖥️ Executable files (e.g., game.exe)

File System Structure

Files live inside directories (folders). The hierarchy looks like a tree:

  • / (root)
  • ├── home/
  • │ ├── alice/
  • │ │ └── notes.txt
  • │ └── bob/
  • │ └── photo.png
  • └── var/

Each file has a path that tells the system where to find it.

File Operations

  1. Create – Allocate space and give a name.
  2. Read – Retrieve data for use.
  3. Write – Modify or add data.
  4. Delete – Remove data permanently.

In programming, these are usually performed with functions like open(), read(), write(), and close().

File Attributes

Attribute Description
Name Unique identifier within its directory.
Size ($size$) Number of bytes stored.
Permissions ($permissions$) Who can read, write, or execute.
Timestamp ($timestamp$) When the file was created/modified.

File Storage Basics

Physical storage is broken into blocks or sectors. A file’s data is spread across these blocks, which the operating system keeps track of.

Analogy: Imagine a file as a book. Each page (block) is stored in a specific location on the shelf (disk). The library catalog (file system) tells you which shelf and which slot each page is in.

Why Files Are Essential

  • Persistence – Data remains after power‑off.
  • Organization – Group related data together.
  • Sharing – Transfer files between devices.
  • Security – Permissions control access.

Without files, a computer would be like a chalkboard that disappears when the lights go out.

Examination Tips

Key terms to remember: file, directory, path, permissions, timestamp, block, sector.

Sample question: Explain how file permissions protect data on a multi‑user system.

Practice: Write a short program that creates a file, writes a line of text, reads it back, and then deletes the file.

Use the analogy of a digital library to explain file organization and permissions.

Revision

Log in to practice.

2 views 0 suggestions