File Management
File management is the function of an operating system that handles the creation, organization, storage, access, modification, protection, and deletion of files.
In simple words:
File management is how the OS manages files from creation to deletion.
The previous topic, File System, explained how files are organized on storage.
Now File Management focuses more on what the OS does with those files.
1. Why Is File Management Needed?
Imagine your computer has:
Documents Pictures Videos Programs Databases Music
The OS needs to provide mechanisms to:
- Create files
- Open files
- Read files
- Write files
- Modify files
- Rename files
- Copy files
- Move files
- Delete files
- Control permissions
- Track file information
Without file management, applications would have to directly manage storage devices themselves.
2. Basic File Management Architecture
User ↓ Application ↓ File System ↓ File Management ↓ Storage Management ↓ Device Driver ↓ SSD / HDD
A more realistic Linux-style flow:
Application ↓ open("notes.txt") ↓ System Call ↓ VFS ↓ Filesystem ↓ Block Layer ↓ Device Driver ↓ SSD/HDD
3. What Is a File?
A file is a named collection of related information stored on secondary storage.
Examples:
notes.txt photo.jpg video.mp4 program.exe database.db report.pdf
A file can contain:
- Text
- Images
- Audio
- Video
- Program code
- Database records
- Configuration data
4. File Attributes
The OS maintains information about every file.
These are called file attributes or metadata.
Example:
report.pdf Name: report.pdf Size: 2 MB Type: PDF Owner: uday Permissions: rw-r--r-- Created: ... Modified: ... Accessed: ...
Important attributes include:
| Attribute | Purpose |
|---|---|
| Name | Identifies the file |
| Type | Indicates the file type |
| Size | File size |
| Location | Where data is stored |
| Owner | User who owns it |
| Permissions | Access control |
| Timestamps | Creation/modification/access information |
| Protection | Security information |
5. File Operations
An operating system provides several basic operations.
File Operations │ ├── Create ├── Open ├── Read ├── Write ├── Append ├── Seek ├── Close ├── Rename ├── Copy ├── Move └── Delete
Let's understand each.
6. Create a File
The OS can create a new file.
Example:
notes.txt
Conceptually:
Application ↓ Create file ↓ OS ↓ Allocate metadata ↓ Create directory entry ↓ File exists
In Linux, a program can use a system call such as:
open("notes.txt", O_CREAT);
7. Open a File
Before a program can normally read or write a file, it opens it.
Example:
open("notes.txt")
The OS:
- Finds the file.
- Checks permissions.
- Locates its metadata.
- Creates/updates an open-file entry.
- Gives the process a handle or file descriptor.
Linux example:
int fd = open("notes.txt", O_RDONLY);
Suppose:
fd = 3
Then the process can use:
read(3, ...)
8. File Descriptor
A file descriptor (FD) is a small integer used by a process to refer to an open file or another I/O resource in Unix/Linux.
Example:
fd = 3
Then:
read(3, ...) write(3, ...) close(3)
Standard descriptors:
0 → stdin 1 → stdout 2 → stderr
Example:
Keyboard → stdin Terminal → stdout Terminal → stderr
9. File Handle
Windows commonly uses the concept of a handle to refer to an opened object.
Conceptually:
Application ↓ File Handle ↓ OS ↓ File
So Linux commonly exposes:
File Descriptor
while Windows APIs commonly expose:
Handle
The underlying concept is similar: the process gets an OS-managed reference to an opened resource.
10. Read Operation
The read operation transfers data from a file into a process's memory.
Storage ↓ File ↓ OS ↓ RAM ↓ Application
Example:
read(fd, buffer, 100);
Meaning conceptually:
Read up to 100 bytes from the file associated with
fdintobuffer.
11. Write Operation
The write operation transfers data from a process to a file.
Application ↓ RAM / Buffer ↓ OS ↓ Filesystem ↓ Storage
Example:
write(fd, buffer, 100);
12. Append Operation
Appending means adding data to the end of an existing file.
Suppose:
notes.txt Hello
Append:
World
Result:
Hello World
The existing data isn't overwritten.
13. Seek Operation
Seek changes the current position from which the next read or write occurs.
Example:
File: ABCDEFGHIJKLMNOPQRSTUVWXYZ ^ position = 0
Seek to position 10:
ABCDEFGHIJKLMNOPQRSTUVWXYZ ^ position 10
This is important for random/direct access.
14. Close Operation
After finishing with a file, the application should close it.
open() ↓ read/write ↓ close()
Example:
close(fd);
Closing releases OS resources associated with that open file.
15. Delete a File
Deleting removes a file's directory reference and eventually allows its storage space to be reused, depending on the filesystem semantics.
Linux:
rm notes.txt
Conceptually:
Directory ↓ notes.txt ↓ Remove reference ↓ Space becomes reusable
On Unix-like systems, an open file can have interesting behavior: deleting a filename does not necessarily immediately destroy the underlying data if a process still has it open.
16. Rename
A file can be renamed without necessarily changing its contents.
Example:
old.txt
becomes:
new.txt
Linux:
mv old.txt new.txt
The same command can also move a file to another directory.
17. Copy vs Move
Copy
Creates another file containing the same data.
A.txt ↓ Copy ↓ B.txt
Now:
A.txt → original B.txt → separate copy
Move
Changes the file's directory/location reference.
Documents/A.txt ↓ Move ↓ Downloads/A.txt
Depending on the filesystem and operation, moving within the same filesystem can often be mostly a metadata/directory operation rather than copying all file data.
18. File Access Methods
There are three important access methods.
1. Sequential Access
Data is accessed from beginning to end.
1 → 2 → 3 → 4 → 5
Example:
Reading a text file from beginning to end
Useful for:
- Logs
- Audio/video streams
- Sequential data processing
2. Direct / Random Access
The program can jump directly to a particular location.
1 → 10 → 50 → 100
Example:
Database record access
3. Indexed Access
An index helps locate records or blocks.
Index ├── Record 1 → Location A ├── Record 2 → Location C └── Record 3 → Location F
This can provide efficient searching.
19. File Types
Operating systems recognize different kinds of files.
Common categories:
Regular files
Examples:
.txt .jpg .pdf .mp4 .exe .py
Directory files
Represent directories.
Documents/ Downloads/ Pictures/
Device files
Common in Unix/Linux.
Examples conceptually:
/dev/sda /dev/tty
Symbolic links
A symbolic link points to another pathname.
shortcut → target
20. Linux File Types
In Linux, the first character of a long listing can indicate the file type.
Example:
-rw-r--r--
First character:
-
means regular file.
Directory:
drwxr-xr-x
First character:
d
Symbolic link:
lrwxrwxrwx
First character:
l
21. File Permissions
File management also includes access control.
Linux uses:
r = read w = write x = execute
Example:
-rwxr-xr--
Breakdown:
Owner → rwx Group → r-x Others → r--
So:
Owner = read + write + execute Group = read + execute Others = read
22. Access Control
The OS checks whether a process is allowed to perform an operation.
Example:
Application ↓ "Open secret.txt" ↓ Permission check ↓ Allowed? / \ Yes No ↓ ↓ Open Denied
Possible permissions:
Read Write Execute
More advanced systems can use Access Control Lists (ACLs).
23. File Ownership
Unix/Linux files generally have:
Owner Group
Example:
-rw-r----- uday developers notes.txt
Conceptually:
Owner → uday Group → developers
Permissions can then be applied according to:
Owner Group Others
24. Open File Table
The OS needs to keep track of files currently opened by processes.
Conceptually:
Process A | +── FD 3 ──→ Open File Table | ↓ notes.txt
The open-file information may include:
- Current file position
- Access mode
- Reference count
- File metadata reference
There can be multiple layers of tables depending on the OS design.
25. File Descriptor Table
Each process can have a file descriptor table.
Example:
Process A FD Resource ---------------------- 0 stdin 1 stdout 2 stderr 3 notes.txt 4 data.db
When:
fd = open("notes.txt", ...);
the OS may return:
3
Then:
read(3, buffer, 100);
means read from the resource associated with descriptor 3.
26. File Sharing
Multiple processes may open the same file.
Example:
Process A ──┐ ├──→ data.txt Process B ──┘
This creates synchronization concerns if both processes write simultaneously.
For example:
Process A → Write "ABC" Process B → Write "XYZ"
Without proper coordination, the resulting data may not be what either process expected.
This connects file management with:
Synchronization and concurrency
27. File Locking
To prevent conflicting access, the OS or applications can use file locks.
Two common conceptual types:
Shared lock
Multiple readers may access the file.
Reader A ──┐ Reader B ──┼──→ File Reader C ──┘
Exclusive lock
Only one writer/accessor is allowed according to the locking mechanism.
Process A ──→ File Process B ──X
File locking is important for:
- Databases
- Log files
- Configuration files
- Multi-process applications
28. File Buffering
Reading/writing directly to storage for every small operation can be inefficient.
The OS often uses buffers/cache.
Application ↓ Buffer / Cache ↓ Filesystem ↓ Storage
For example, an application may write several small pieces of data, which can be handled more efficiently through buffering.
29. File Caching
The OS can keep frequently used file data in RAM.
First access: Application ↓ RAM cache → miss ↓ Storage ↓ RAM cache
Later:
Application ↓ RAM cache → hit ↓ Data
RAM is much faster than storage, so caching improves performance.
30. File Allocation
The OS must know where a file's data is stored.
Common allocation methods:
Contiguous
[10][11][12][13][14]
Linked
[10] → [25] → [7] → [31]
Indexed
Index ↓ 10 25 7 31
These were introduced in the filesystem topic and are especially important for understanding file management.
31. Free Space Management
When a file is deleted, its blocks become available.
The filesystem must track free blocks.
Common methods include:
Bitmap
Block: 1 2 3 4 5 6 7 8 Used: 1 1 0 1 0 0 1 1
Where:
1 = used 0 = free
Free list
Free blocks: 3 → 5 → 6
The filesystem can use this information when allocating space for new files.
32. File System Journaling and File Management
When important filesystem metadata is changed:
Create file Delete file Rename file Allocate blocks Update metadata
a journaling filesystem can record operations in a journal.
Conceptually:
File operation ↓ Journal ↓ Filesystem metadata ↓ Storage
This helps recover from certain crashes or power failures.
33. File Management and System Calls
Applications normally don't directly manipulate disk sectors.
They request OS services through system calls/APIs.
Typical Unix/Linux operations include:
open() read() write() lseek() close() rename() unlink() stat()
Flow:
Application ↓ Library/API ↓ System Call ↓ Kernel ↓ File System ↓ Storage
34. Example: Reading a File
Suppose a program wants to read:
/home/uday/notes.txt
The conceptual process:
1. Application requests open() ↓ 2. Kernel receives request ↓ 3. Filesystem resolves path ↓ 4. Permission check ↓ 5. File metadata is located ↓ 6. Open-file information created ↓ 7. File descriptor returned ↓ 8. Application calls read() ↓ 9. Filesystem locates data ↓ 10. Data comes from cache or storage ↓ 11. Data copied to application buffer
35. Example: Writing a File
Suppose:
Application wants to save: "Hello World"
Flow:
Application ↓ write() ↓ Kernel ↓ Filesystem ↓ Buffer/cache ↓ Allocate blocks if needed ↓ Storage
Depending on caching and synchronization semantics, the data may initially reside in memory before being persisted to the storage device.
36. File Management in Linux
Common commands:
List files
ls
Create file
touch file.txt
Read file
cat file.txt
Copy
cp file.txt backup.txt
Move/rename
mv file.txt new.txt
Delete
rm file.txt
Create directory
mkdir test
Remove directory
rmdir test
We'll study Linux commands separately later in your roadmap.
37. File Management in Windows
Common commands include:
dir
List files.
type file.txt
Display text file.
copy file.txt backup.txt
Copy.
move file.txt new.txt
Move/rename.
del file.txt
Delete.
mkdir test
Create directory.
These will be covered in more detail in the Windows command section later.
38. File Management vs Memory Management
Don't confuse these.
| File Management | Memory Management |
|---|---|
| Manages files | Manages RAM |
| Secondary storage | Main memory |
| Files/directories | Processes/pages/frames |
| File allocation | Memory allocation |
| File permissions | Memory protection |
| Disk/SSD | RAM |
| open/read/write | allocate/free/map |
Example:
File Management ↓ SSD/HDD Memory Management ↓ RAM
39. File Management vs Storage Management
File Management
Works with:
Files Directories Metadata Permissions File access
Storage Management
Deals more broadly with:
Disk/SSD Blocks Partitions Volumes Free space I/O scheduling Storage allocation
They work together.
40. Complete File Management Model
USER ↓ APPLICATION ↓ File API / System Call ↓ File Management ↓ ┌──────────────┼──────────────┐ ↓ ↓ ↓ File Metadata Permissions Open Files ↓ ↓ ↓ └──────────────┼──────────────┘ ↓ File System ↓ Block Allocation ↓ Storage I/O ↓ SSD / HDD
🧠 Important Exam Questions
Q1. What is file management?
File management is an operating system function responsible for creating, organizing, accessing, modifying, protecting, and deleting files and directories.
Q2. What are common file operations?
Create Open Read Write Seek Close Rename Delete
Q3. What is a file descriptor?
A file descriptor is a small integer used by a Unix/Linux process to identify an open file or other I/O resource.
Q4. What is file metadata?
Metadata is information describing a file, such as its name, size, owner, permissions, location, and timestamps.
Q5. What are file access methods?
Sequential Direct/Random Indexed
Q6. What is file protection?
File protection controls which users or processes can access or modify files.
🔥 Final Revision
Remember this flow:
FILE MANAGEMENT │ ┌────────────────┼─────────────────┐ ↓ ↓ ↓ Create Access Delete ↓ ↓ ↓ Open Read / Write Remove ↓ ↓ Metadata Seek ↓ ↓ Permissions Close │ ↓ File System ↓ Storage
The most important concepts:
File ↓ Attributes / Metadata ↓ Create ↓ Open ↓ File Descriptor / Handle ↓ Read / Write ↓ Seek ↓ Close ↓ Rename / Copy / Move ↓ Delete ↓ Permissions / Protection ↓ File Allocation ↓ Free-Space Management ↓ Caching / Buffering
🧠 Memory trick
“Create → Open → Read/Write → Seek → Close → Rename/Move → Delete → Protect.”