A Command Line Interface (CLI) based File System Simulator built in Java that mimics both a virtual file system and interacts with the real operating system file system.
This project demonstrates core Operating System concepts such as:
- File & Directory Management
- Disk Block Allocation
- Tree Structures
- Persistence using Serialization
- Create/Delete directories and files
- Navigate using
cd,pwd - Read & write file content
- Tree structure visualization
- File search (
find) - Disk block allocation simulation
- Persistent storage (save/load system state)
- Browse real directories
- Create/Delete real files & folders
- Navigate system directories
- Safe delete (prevents deleting non-empty folders)
- Command auto-completion (
auto) - Path-based suggestions (like terminal)
- Color-coded output
- Error handling for invalid commands
- Disk usage visualization
- Tree Data Structure
- File Allocation (Contiguous Allocation)
- Serialization (
ObjectOutputStream,ObjectInputStream) - Recursion (for
find,tree) - CLI Command Parsing
FileSystemSimulator/
│
├── cli/
│ └── CommandHandler.java
│
├── filesystem/
│ ├── FileSystem.java
│ └── FileNode.java
│
├── disk/
│ └── DiskManager.java
│
├── utils/
│ └── Colors.java
│
├── data/
│ └── filesystem.dat (auto-created)
│
└── main/
└── Main.java
javac -d out src/main/Main.java src/main/cli/*.java src/main/filesystem/*.java src/main/disk/*.java src/main/utils/*.java
java -cp out main.Main
- System automatically loads previous state on start
- System saves on exit
exit
→ System saved.
Data stored in:
/data/filesystem.dat
| Command | Description |
|---|---|
| mkdir | Create directory |
| cd | Change directory |
| cd .. | Go back |
| ls | List contents |
| pwd | Show current path |
| touch | Create empty file |
| create | Create file with size |
| write | Write content |
| cat | Read file |
| rm | Delete file/folder |
| disk | Show disk usage |
| free | Show free blocks |
| find | Search file |
| tree | Show structure |
| Command | Description |
|---|---|
| real-pwd | Show real path |
| real-ls | List real directory |
| real-mkdir | Create folder |
| real-touch | Create file |
| real-rm | Delete file/folder |
| real-cd | Change directory |
| Command | Description |
|---|---|
| auto | Auto-complete |
| help | Show commands |
| clear | Clear screen |
| exit | Save & exit |
- Fixed number of blocks (default: 50)
- Contiguous allocation strategy
- Each file stores allocated block list
- Disk rebuilt on system load
Example:
Disk Status:
[X][X][ ][ ][X]...
mkdir docs
cd docs
touch file1.txt
write file1.txt
cat file1.txt
disk
exit
- No permissions system
- No multi-user support
- Simple allocation strategy only
- No file compression
- Recursive delete (
rm -r) - File rename / move (
mv) - Copy files (
cp) - Fragmentation simulation
- Defragmentation feature
- Command history (↑ ↓ keys)
- Real TAB auto-complete
Yugal Mahajan
Give it a ⭐ on GitHub and feel free to contribute!