operating-system-file-system-experiment
Experiment Purpose
Through this experiment, students will deeply understand the principles and operational methods of the file system in operating systems, master the implementation ways of core functions such as file management, directory operations, and permission control, and verify theoretical knowledge through practical operations.
Experiment Environment
- Operating System: Linux (e.g., Ubuntu 20.04)
- Tools: Terminal commands (ls, cd, touch, mkdir, chmod, cp, rm etc.)
- File System Type: ext4 (default Linux file system)
Experiment Content
1. File System Basic Concepts
- Function of File System: Manage disk space, organize file structures, and provide a unified access interface.
- Key Concepts:
- Inode: Stores file metadata (permissions, size, timestamp etc.).
- Directory Structure: Root directory (/), user home directory (~), system directories (e.g., /bin, /etc).
- Superblock: Records global system information (total block count, available space etc.).
2. File and Directory Operations
- Create File: Use
touch filenamecommand. - Create Directory: Use
mkdir directory_namecommand. - Switch Directory: Use
cdcommand (e.g.,cd /home/user). - View Directory Contents: Use
lscommand (e.g.,ls -lfor detailed information).
3. File Permission Management
- Permission Types:
- Read (r): Allow viewing file contents.
- Write (w): Allow modifying file contents.
- Execute (x): Allow running executable files.
- Permission Settings:
- Use
chmodcommand (e.g.,chmod 755 filenameto set permissions). - Use
chowncommand (e.g.,chown user:group filenameto change owner).
- Use
Experiment Steps
- Initialize File System
- Use
df -hto check disk space usage. - Use
df -ito verify inode resource availability.
- Use
- Create Test Files and Directories
- Create file:
touch testfile.txt - Create directory:
mkdir testdir - Switch directory:
cd testdir
- Create file:
- File Operations Practice
- Copy file:
cp testfile.txt . - Delete file:
rm testfile.txt - Delete directory:
rm -r testdir
- Copy file:
- Permission Settings Test
- Set file permissions:
chmod 644 testfile.txt - Verify permissions:
ls -l testfile.txt - Modify file owner:
chown user:group testfile.txt
- Set file permissions:
Experiment Results Analysis
- File System Status: Confirmed via
dfcommand that disk space is within limits. - Permission Validation:
- Only owner can read/write file (644 permissions).
- Other users can only read file (444 permissions).
- Directory Structure: Verified that created files and directories exist in expected paths.
Common Issues and Solutions
- Issue 1: File cannot be read
- Cause: Permission settings are incorrect.
- Solution: Use
chmodto fix permissions (e.g.,chmod 644 filename).
- Issue 2: Directory cannot be deleted
- Cause: Directory contains files or is occupied by other processes.
- Solution: Delete files inside the directory first, or use
rm -rto force delete.
- Issue 3: Inode exhaustion
- Cause: Too many files.
- Solution: Delete redundant files or expand the file system.
Experiment Summary
Through this experiment, students will master the operational methods of the Linux file system, understand the importance of file permission management, and independently complete the creation, modification, and deletion of files and directories. Attention should be paid to proper permission settings and reasonable use of disk resources to lay a foundation for subsequent studies in process management and storage management.