Skip to content

Tmq244/MiniFileExplorer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MiniFileExplorer

A lightweight, terminal-based file manager built in C++17 that provides core file system operations similar to Linux command-line tools.

Overview

MiniFileExplorer is a command-line file management tool that allows users to navigate, create, delete, search, and manipulate files and directories through an interactive terminal interface. It's designed to be simple, efficient, and user-friendly.

Features

Basic Operations

  • Directory Navigation: Change directories with cd, support for relative/absolute paths and ~ for home directory
  • File Listing: List directory contents with detailed information (name, type, size, modification time)
  • File Creation: Create empty files with touch
  • Directory Creation: Create directories with mkdir, recursive creation with mkdir -p
  • File Deletion: Delete files with confirmation prompt using rm, recursive deletion with rm -r
  • Directory Deletion: Delete empty directories with rmdir
  • File Information: Get detailed file/directory metadata with stat

Advanced Features

  • 🔍 Recursive Search: Case-insensitive file/folder name search across subdirectories with search
  • 📋 File Operations: Copy and move files/folders; recursive directory copy with cp -r; hard/symlink creation with ln
  • 📊 Directory Analysis: Calculate total directory size with automatic unit conversion (B/KB/MB)
  • 🔄 Sorting Options: Sort listings by size (ls -s) or modification time (ls -t); sort file contents with sort
  • 👁️ File Content Viewing: Display file contents with cat, view first/last lines with head/tail
  • 📝 File Statistics: Count lines, words, and bytes with wc; filter duplicate lines with uniq
  • 🌲 Directory Tree: Visualize directory structure with tree
  • 🔎 Content Search: Search inside file contents with grep (line numbers, case-insensitive)
  • 🗂️ Multi-filter Find: Find files and directories by name/type/extension/size with find (supports glob patterns with -name *.cpp)
  • 🔐 Permission Management: View and change Unix file permissions with ls -l and chmod
  • 📄 File Diff: Compare two files line by line with color-coded output using diff

User Experience

  • 🎯 Interactive Command Prompt: Compact shell-style prompt showing current directory
  • 📖 Help System: Built-in help command listing all available commands
  • Error Handling: Comprehensive error messages for invalid operations
  • 🔒 Safety Features: Confirmation prompts for destructive operations
  • 🎨 Colored Output: ANSI-colored ls and tree listings — directories in blue, executables in green, symlinks in cyan, hidden files in gray, keyword matches in red
  • ⌨️ Command History: Up/Down arrow keys to navigate previous commands; history command to list them (implemented via termios, no external dependencies)
  • 🔡 Tab Completion: Press Tab to auto-complete command names and file paths; shows all matches on double-Tab
  • 🌐 Glob Expansion: Use * and ? wildcards in any command (ls *.txt, rm *.log)
  • 🏷️ Command Aliases: Define session-scoped shortcuts with alias/unalias

Requirements

  • C++ Compiler with C++17 support:
    • GCC 7.0 or higher
    • Clang 5.0 or higher
    • MSVC 2017 or higher
  • CMake version 3.10 or higher
  • Standard C++ Filesystem Library (included in C++17)
  • POSIX termios for arrow-key history (available on Linux/macOS by default)

Building the Project

Quick Build

# Clone or navigate to the project directory
cd MiniFileExplorer

# Create build directory and compile
mkdir -p build
cd build
cmake ..
make

# Run the application
./MiniFileExplorer

Alternative Build Method

cmake -B build -S .
cmake --build build
./build/MiniFileExplorer

Troubleshooting

If you encounter filesystem library errors with older compilers, uncomment line 17 in CMakeLists.txt:

target_link_libraries(MiniFileExplorer stdc++fs)

Usage

Starting the Application

# Start in current working directory
./MiniFileExplorer

# Start in a specific directory
./MiniFileExplorer /path/to/directory

Interactive Session

Once started, you'll see a shell-style prompt with the current directory:

Welcome to MiniFileExplorer!
Use ↑↓ arrow keys to navigate history. Type 'help' for all commands.

[/home/user/documents] $

Use the Up/Down arrow keys to cycle through previously entered commands.

Command Reference

Navigation Commands

Command Description Example
cd [path] Change directory cd documents, cd .., cd ~
cd Switch to home directory cd
ls List directory contents ls
ls -a Include hidden files (dotfiles) ls -a
ls -l Long format with permissions ls -l
ls -s Sort by size (descending) ls -s
ls -t Sort by modification time ls -t
pwd Print current working directory pwd
tree [dir] Display directory as a tree tree src
tree [dir] -a Include hidden files in tree tree -a
tree [dir] -L N Limit tree depth to N levels tree -L 2

File Operations

Command Description Example
touch [filename] Create an empty file touch note.txt
mkdir [foldername] Create a directory mkdir archive
mkdir -p [path] Create directories recursively mkdir -p a/b/c
rm [filename] Delete a file (with confirmation) rm old.txt
rm -r [directory] Recursively delete a directory rm -r tmp/
rmdir [foldername] Delete an empty directory rmdir temp
stat [name] Show detailed file/directory info stat note.txt
chmod [mode] [file] Change file permissions chmod 755 script.sh
ln [target] [link] Create a hard link ln file.txt hard.txt
ln -s [target] [link] Create a symbolic link ln -s /etc/hosts hosts

File Content Commands

Command Description Example
cat [file] Display full file contents cat notes.txt
cat [file] -n Display with line numbers cat notes.txt -n
head [file] Show first 10 lines head notes.txt
head [file] -n N Show first N lines head notes.txt -n 5
tail [file] Show last 10 lines tail notes.txt
tail [file] -n N Show last N lines tail notes.txt -n 20
wc [file] Count lines, words, and bytes wc notes.txt
sort [file] Sort file lines alphabetically sort names.txt
sort [file] -r Sort in reverse order sort names.txt -r
sort [file] -n Sort numerically sort sizes.txt -n
uniq [file] Remove adjacent duplicate lines uniq sorted.txt
uniq [file] -c Show duplicate count prefix uniq sorted.txt -c
grep [kw] [file] Search file contents for keyword grep TODO main.cpp
grep [kw] [file] -n Show matching line numbers grep TODO main.cpp -n
grep [kw] [file] -i Case-insensitive match grep error log.txt -i
diff [file1] [file2] Compare two files line by line diff old.txt new.txt

Search & Discovery

Command Description Example
search [keyword] Search file/folder names recursively search .txt
find Find with filters (combinable) see below
find [dir] -name [pat] Match filename substring find src -name util
find [dir] -type f|d Filter by file or directory find . -type f
find [dir] -ext [.xxx] Filter by file extension find src -ext .cpp
find [dir] -size +N|-N Filter by size in KB find . -size +100

Advanced Operations

Command Description Example
cp [source] [target] Copy a file cp file.txt backup/
cp -r [dir] [target] Recursively copy a directory cp -r src/ src_backup/
mv [source] [target] Move/rename file or folder mv old.txt new.txt
du [foldername] Calculate directory size du documents

Alias Commands

Command Description Example
alias [name=value] Define a command alias alias ll=ls
alias [name] Show a specific alias alias ll
alias List all defined aliases alias
unalias [name] Remove an alias unalias ll

Utility Commands

Command Description
help Show all available commands
history Show command history
clear Clear the terminal screen
exit Exit MiniFileExplorer

Usage Examples

Example 1: Basic Navigation and File Creation

[/home/user] $ cd documents
[/home/user/documents] $ touch notes.txt
Created file: notes.txt
[/home/user/documents] $ mkdir -p archive/2024
Created directory: archive/2024
[/home/user/documents] $ ls
Name                           Type    Size(B)         Modify Time
notes.txt                      File    0               2024-05-20 14:30:00
archive/                       Dir     -               2024-05-20 14:30:15

Example 2: File Permissions

[/home/user/documents] $ ls -l
Permissions Type    Size(B)        Modify Time           Name
--------------------------------------------------------------------------------
rw-r--r--  File    1024           2024-05-20 15:10:23   notes.txt
rwxr-xr-x  Dir     -              2024-05-20 14:30:15   archive/

[/home/user/documents] $ chmod 755 notes.txt
Permissions changed: notes.txt -> 755 (rwxr-xr-x)

Example 3: Directory Tree

[/home/user/documents] $ tree archive -L 2
archive/
├── 2024/
│   ├── jan.txt
│   └── feb.txt
└── readme.md

Example 4: File Content and grep

[/home/user/documents] $ cat notes.txt -n
     1  Hello, world!
     2  This is a TODO item.

[/home/user/documents] $ grep TODO notes.txt -n -i
    2: This is a TODO item.
1 match(es) found.

Example 5: Advanced Find

[/home/user] $ find documents -ext .txt -size -10
/home/user/documents/notes.txt (File)
/home/user/documents/archive/2024/jan.txt (File)
2 result(s) found.

[/home/user] $ find documents -type d
/home/user/documents/archive (Dir)
/home/user/documents/archive/2024 (Dir)
2 result(s) found.

Example 6: Command History

[/home/user] $ history
   1  ls -l
   2  cd documents
   3  grep TODO notes.txt -n
   4  chmod 755 script.sh

Use ↑/↓ arrow keys to recall previous commands directly at the prompt.

Example 7: File Diff

[/home/user/documents] $ diff v1.txt v2.txt
--- v1.txt
+++ v2.txt
  Hello, world!
- This is the old line.
+ This is the new line.
  Goodbye.

Example 8: Aliases and Glob Expansion

[/home/user/documents] $ alias ll=ls -l
Alias set: ll='ls'
[/home/user/documents] $ ll
Permissions Type    Size(B)   ...

[/home/user/documents] $ ls *.txt
notes.txt  File  ...
archive.txt  File  ...

[/home/user/documents] $ rm *.log
Are you sure to delete error.log? (y/n) y
Deleted: error.log

Example 9: Tab Completion

[/home/user/documents] $ ca<TAB>
cat  cat  cd
[/home/user/documents] $ cat no<TAB>
[/home/user/documents] $ cat notes.txt

Example 10: Safe Deletion

[/home/user/documents] $ rm old.txt
Are you sure to delete old.txt? (y/n) y
Deleted: old.txt

[/home/user/documents] $ rm -r tmp/
Are you sure to recursively delete directory 'tmp/' and all its contents? (y/n) y
Deleted: tmp/

Project Structure

MiniFileExplorer/
├── CMakeLists.txt          # Build configuration
├── README.md               # This file
├── src/                    # Source code directory
│   ├── main.cpp           # Application entry point
│   ├── App.h/cpp          # Main application loop + line editor
│   ├── Command.h/cpp      # Command registry system
│   ├── Commands.h/cpp     # Built-in command implementations
│   ├── CommandParser.h/cpp # Input tokenization
│   ├── FileSystemContext.h # Application state (incl. command history)
│   ├── FileInfo.h         # File metadata structure
│   └── FsUtil.h/cpp       # File system utilities
└── build/                 # Build directory (generated)

Architecture

Component Overview

The project follows a modular architecture with clear separation of concerns:

  1. Application Layer (App.h/cpp): Main event loop, termios-based line editor with history navigation
  2. Command System (Command.h/cpp, Commands.h/cpp): Command registration and execution
  3. Parser Layer (CommandParser.h/cpp): Input tokenization
  4. File System Layer (FsUtil.h/cpp): Low-level file operations
  5. Data Structures (FileSystemContext.h, FileInfo.h): State management including command history

Design Patterns

  • Command Pattern: Commands are encapsulated as handler functions
  • Registry Pattern: Centralized command lookup and management
  • Namespace Organization: File utilities grouped in fsutil namespace

Error Messages

The application provides clear error messages for common issues:

  • Invalid directory: [path] - Directory doesn't exist
  • Not a directory: [path] - Path points to a file
  • File already exists: [name] - Cannot create duplicate file
  • Directory not empty: [name] - Cannot delete non-empty directory
  • Target not found: [name] - File/directory doesn't exist
  • Source not found - Source path doesn't exist
  • File exists in target: Overwrite? (y/n) - Overwrite confirmation
  • Invalid mode: [mode] - chmod received non-octal input

Development

Adding New Commands

To add a new command:

  1. Add the command registration in src/Commands.cpp:
registry.registerCommand(
    "mycommand",
    "Description of my command",
    [](const vector<string>& args, FileSystemContext& ctx) {
        // Implementation here
    }
);
  1. Implement file system operations in src/FsUtil.cpp if needed.

Building for Development

# Debug build
cmake -DCMAKE_BUILD_TYPE=Debug -B build .
cmake --build build

# Release build
cmake -DCMAKE_BUILD_TYPE=Release -B build .
cmake --build build

License

This project is developed as an educational file manager demonstration.

Contributing

This is an educational project. Suggestions and improvements are welcome!

Future Enhancements

Potential features for future versions:

  • Configuration file support (.miniferc) — persist aliases and settings across sessions
  • zip/unzip — archive support
  • Pipe operator (|) — chain commands like cat file.txt | grep TODO
  • Multi-column ls output
  • Use Rust to rewrite this project

Acknowledgments

Built using:

  • C++17 Standard Library
  • <filesystem> library for file operations
  • <termios.h> for terminal raw mode (arrow-key history)
  • CMake for build configuration

Note: This is a terminal-based application. Ensure your terminal supports UTF-8 encoding for best display results.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages