1. Introduction

At first glance, files appear fundamentally different:

  • .txt → Text document

  • .mp4 → Video file

  • .exe → Executable program

  • .jpg → Image

However, from the operating system's perspective, all files are ultimately stored as sequences of bytes.

The difference lies not in storage, but in interpretation.

Key Insight

Same Bytes
      ↓
Different Interpretation
      ↓
Different File Types

2. What is a File Type?

A file type is a classification that determines how the contents of a file should be interpreted, processed, and used.

Definition

A file type specifies the format and intended use of a file.

Key Idea

File Type = Meaning Assigned to Data

The actual storage remains a sequence of bytes.

3. Operating System Perspective vs User Perspective

Operating System Perspective

For the OS:

File = Sequence of Bytes

The OS does not inherently understand:

  • Videos

  • Music

  • Documents

It only stores and retrieves bytes.

User/Application Perspective

Applications interpret those bytes differently.

For example:

01001000 01101001

can be interpreted as:

"Hi"

in a text file.

Or it may represent completely different binary data in another file format.

Key Insight

Meaning is determined by the application, not by the storage system.

4. Major File Types

4.1 Text Files

Definition

Files containing human-readable characters.

Characteristics

  • Readable by users

  • Encoded using ASCII or UTF-8

  • Easy to edit and debug

Examples

.txt
.c
.cpp
.log
.py
.java

Example Content

Hello World

Advantages

  • Portable

  • Human-readable

  • Easy debugging

Key Insight

Text files prioritize readability over storage efficiency.

4.2 Binary Files

Definition

Files containing data in machine-readable format.

Characteristics

  • Not directly readable by humans

  • Compact representation

  • Faster processing

Examples

.bin
.dat
.jpg
.png
.mp4
.mp3

Advantages

  • Efficient storage

  • Faster access

  • Better performance

Disadvantages

  • Difficult to inspect manually

  • Requires specialized software

Key Insight

Binary files optimize performance rather than readability.

4.3 Executable Files

Definition

Files containing machine instructions that can be executed by the CPU.

Characteristics

  • Loaded into memory

  • Executed as processes

  • Contain compiled machine code

Examples

Windows

.exe

Linux

ELF Executables

Execution Flow

Executable File
       ↓
Loaded into Memory
       ↓
Process Created
       ↓
CPU Executes Instructions

Key Insight

Executable files are stored like ordinary files but receive special treatment during execution.

4.4 Object Files

Definition

Intermediate files produced during compilation.

Characteristics

  • Contain machine code

  • Not directly executable

  • Used by linker

Examples

Linux

.o

Windows

.obj

Compilation Flow

Source Code
      ↓
Compiler
      ↓
Object File
      ↓
Linker
      ↓
Executable File

Purpose

Facilitates modular program development.

4.5 Directory Files

Definition

Special files that store information about other files.

Contents

Typically store:

  • File names

  • inode numbers

  • References to file metadata

Example

Documents/
Downloads/
Pictures/

Important Insight

Directories are also files.

They simply contain structured information rather than user data.

4.6 Special Files (Very Important)

UNIX systems treat devices and communication channels as files.

UNIX Philosophy

Everything is a File

4.6.1 Character Special Files

Used for stream-oriented devices.

Examples

  • Keyboard

  • Terminal

  • Serial port

Characteristics

Data transferred character by character.

Example Device Files

/dev/tty
/dev/console

4.6.2 Block Special Files

Used for block-oriented devices.

Examples

  • Hard disks

  • SSDs

  • USB drives

Characteristics

Data transferred in blocks.

Example Device Files

/dev/sda
/dev/nvme0n1

Key Insight

Hardware devices can be accessed using standard file operations:

open()
read()
write()
close()

4.7 FIFO Files (Named Pipes)

Definition

Special files used for inter-process communication (IPC).

Purpose

Allow one process to send data directly to another.

Communication Flow

Process A
      ↓
   FIFO
      ↓
Process B

Characteristics

  • Temporary communication channel

  • Managed by OS

  • Behaves like a file

4.8 Socket Files

Definition

Special files used for network and inter-process communication.

Uses

  • Client-server applications

  • Network communication

  • Local IPC

Example

/var/run/socket

Key Insight

Sockets enable communication using file-like interfaces.

5. Classification of File Types

Files

├── Text Files
├── Binary Files
├── Executable Files
├── Object Files
├── Directory Files
└── Special Files
      ├── Character Files
      ├── Block Files
      ├── FIFO Files
      └── Socket Files

6. How Operating Systems Identify File Types

6.1 File Extensions

Most users identify file types using extensions.

Examples:

.txt
.jpg
.pdf
.exe

Purpose

Helps applications determine how to open files.

Limitation

Extensions can be renamed and may be misleading.

Example:

virus.exe → virus.txt

The extension changes, but the content remains unchanged.

6.2 Magic Numbers (Advanced)

Many operating systems inspect file headers.

These headers contain unique signatures.

Examples

PDF

%PDF

JPEG

Contains specific byte signatures at the beginning of the file.

Purpose

Provides reliable file identification.

Key Insight

The OS often trusts file content more than extensions.

6.3 Metadata (inode)

File metadata may also contain file type information.

Stored in:

  • inode

  • FCB

This helps the OS distinguish between:

  • Regular files

  • Directories

  • Device files

  • Pipes

  • Sockets

7. Why File Types Matter

7.1 Program Execution

Determines how files are processed.

Example:

.exe → Execute

.txt → Display

.jpg → Render Image

7.2 Security

Prevents accidental execution of inappropriate files.

Example

A text file should not be treated as executable code.

7.3 System Behavior

Special file types trigger unique kernel behavior.

Examples:

  • Device files interact with hardware

  • Pipes enable communication

  • Sockets support networking

8. Real-World Analogy

Imagine a sheet of paper.

The paper itself is identical.

Its meaning depends on interpretation.

The same paper may represent:

  • A letter

  • A contract

  • A drawing

  • A certificate

Similarly:

Same Bytes
      ↓
Different Interpretation
      ↓
Different File Type

Although users see many different file types, the operating system fundamentally stores all files as sequences of bytes. File types exist to define how those bytes should be interpreted, processed, and accessed.