๐ File Management โ Basic Concepts
๐น What Is a File?
A file is a named collection of related data stored on a secondary storage device (like a hard disk or SSD). Files are the primary means by which data is organized and accessed in most operating systems.
Think of a file as a container for storing digital informationโtext, images, videos, program instructions, etc.
๐ What Is File Management?
File management is a function of the operating system that handles the creation, organization, storage, retrieval, naming, sharing, protection, and deletion of files.
๐งฑ 1. Basic File Concepts
Concept | Description |
---|---|
File Name | Human-readable name used to identify the file (e.g., report.docx ) |
File Extension | Indicates the file type (e.g., .txt , .exe , .jpg ) |
File Structure | Way data is organized in a file: byte stream, records, or tree |
File Type | Indicates usageโtext, binary, executable, etc. |
File Attributes | Metadata like creation date, size, owner, permissions |
๐งพ 2. File Attributes (Metadata)
Files have attributes that describe their properties:
- Name โ Unique identifier
- Type โ Format of the data (e.g., text, image)
- Location โ Where on disk the file resides
- Size โ Number of bytes
- Protection โ Access rights (read/write/execute)
- Time stamps โ Created, modified, accessed
๐ 3. File Operations
The OS provides a set of operations for file handling:
Operation | Description |
---|---|
Create | Makes a new file with a unique name |
Open | Prepares a file for reading or writing |
Read | Retrieves data from a file |
Write | Stores data into a file |
Close | Ends access to a file |
Delete | Removes a file from storage |
Rename | Changes a file’s name |
Append | Adds data at the end of a file |
Seek | Moves the file pointer to a specific location |
๐๏ธ 4. File Organization
Files can be organized in different structures:
- Byte Sequence (unstructured stream, like in Unix)
- Record-based (used in databases, fixed-length records)
- Tree Structure (hierarchical, used in XML or JSON)
- Indexed (for fast lookup)
๐๏ธ 5. Directory Structure
Files are stored in directories (folders) to keep things organized. Directory structures include:
Structure | Description |
---|---|
Single-level | All files in one directory |
Two-level | Separate user directories |
Tree-structured | Hierarchical, supports subdirectories (most common) |
Acyclic Graph | Allows shared subdirectories/files |
General Graph | Allows cycles (complex, requires garbage collection) |
๐ 6. File Access Methods
a) Sequential Access
- Data is read/written in order
- Simple but slow for random access
- Example: reading a log file
b) Direct (Random) Access
- Access any part of file directly using seek
- Used in databases, multimedia files
c) Indexed Access
- File has an index table for fast searching
- Common in large databases
๐งฐ 7. File Allocation Methods
How space is allocated on disk for storing files:
Method | Description | Pros & Cons |
---|---|---|
Contiguous | Entire file stored in one block | Fast access, but causes fragmentation |
Linked List | Each block points to the next | No fragmentation, but slow random access |
Indexed | Uses an index block to point to all file blocks | Fast and flexible |
๐ฅ 8. File Protection and Access Control
OS ensures data security through:
- Access Control Lists (ACLs) โ Define user rights (read, write, execute)
- File Permissions โ Unix-style (owner, group, others: rwx)
- Encryption โ Data is scrambled to protect from unauthorized access
- User Authentication โ Ensures only legitimate users access files
๐งช Real-Life Example: Using a Text File
When you open a .txt
file:
- OS checks access permissions
- If allowed, it opens the file and places it in memory
- You read/write data using an application
- On closing, OS updates the fileโs metadata (modified time, size)
๐ Summary
- File management is a core responsibility of any OS.
- It provides a systematic way to store, access, and secure data.
- OS manages files using structures, access methods, operations, and protection mechanisms.
- A robust file system ensures efficiency, security, and data integrity.