A lightweight, custom shell implementation in C with essential command-line utilities. Built from scratch to understand how shells work at a low level using system calls and process management.
cd [directory]- Change directory with home directory support (cd ~)exit- Exit the shell gracefully
echo [text]- Print text to standard outputls [directory]- List files and directories with color coding- ๐ต Blue for directories
- ๐ข Green for files
clear- Clear the terminal screentouch [filename]- Create empty filesedit [filename]- Simple text editor with save/quit functionality
- Real-time current working directory display
- Command parsing and tokenization
- Process management with
fork()andexecv() - Error handling for invalid commands and system calls
- Custom prompt:
Muski-shell: /current/path>
- GCC compiler
- Linux/Unix environment
- Standard C library
-
Clone or navigate to the project directory:
cd /path/to/Muski-shell -
Create the build directory:
mkdir -p build
-
Compile all command utilities:
gcc commands/echo.c -o build/echo gcc commands/ls.c -o build/ls gcc commands/clear.c -o build/clear gcc commands/touch.c -o build/touch gcc commands/edit.c -o build/edit
-
Compile the main shell:
gcc main.c -o terminal
-
Run the shell:
./terminal
Create a build.sh file for easier compilation:
#!/bin/bash
mkdir -p build
gcc commands/echo.c -o build/echo
gcc commands/ls.c -o build/ls
gcc commands/clear.c -o build/clear
gcc commands/touch.c -o build/touch
gcc commands/edit.c -o build/edit
gcc main.c -o terminal
echo "Build complete! Run ./terminal to start."Then run: chmod +x build.sh && ./build.sh
# Display text
echo Hello, World!
# List files in current directory
ls
# List files in specific directory
ls /home/user
# Change directory
cd /path/to/directory
cd ~ # Go to home directory
cd .. # Go to parent directory
# Create empty file
touch myfile.txt
# Clear screen
clear
# Exit shell
exit# Open or create a file
edit myfile.txt
# Editor commands:
:w # Save file
:q # Quit without saving
:wq # Save and quit
:l # List all lines with numbers
:d5 # Delete line 5Muski-shell/
โโโ main.c # Main shell loop and built-in commands
โโโ commands/ # External command implementations
โ โโโ echo.c # Echo command
โ โโโ ls.c # List files with colors
โ โโโ clear.c # Clear terminal
โ โโโ touch.c # Create files
โ โโโ edit.c # Simple text editor
โโโ build/ # Compiled binaries (gitignored)
โโโ terminal # Main shell executable (gitignored)
โโโ .gitignore # Git ignore rules
โโโ README.md # This file
Muski-shell: /home/user/projects>
ls
file1.txt folder1 script.sh README.md
Muski-shell: /home/user/projects>
echo Creating a new file...
Creating a new file...
Muski-shell: /home/user/projects>
touch notes.txt
Muski-shell: /home/user/projects>
edit notes.txt
=== Simple Text Editor ===
edit> This is my first line
Added line 1
edit> This is my second line
Added line 2
edit> :wq
File saved and quit (2 lines)
Muski-shell: /home/user/projects>
cd ~
Muski-shell: /home/user>
exit- Output redirection:
ls > output.txt - Input redirection:
cat < input.txt - Append mode:
echo "text" >> file.txt - Error redirection:
command 2> error.log
- Chain commands:
ls | grep .txt - Multiple pipes:
cat file.txt | grep pattern | wc -l
- Run processes in background:
command & - Job control:
jobs,fg,bg - Process status display
- Arrow key navigation (โ/โ)
historycommand to view past commands!nto execute command n from history- Persistent history across sessions
- Auto-complete file and directory names
- Command name completion
- Path completion with multiple suggestions
- Insert/replace mode switching
- Line editing (insert at position)
- Search and replace functionality
- Undo/redo capability
- Syntax highlighting
- Multiple buffer support
- Ctrl+C to interrupt current process
- Ctrl+Z to suspend processes
- Proper cleanup on signals
fork()- Create child processesexecv()- Execute external commandswait()- Wait for child process completionchdir()- Change working directorygetcwd()- Get current working directoryopendir(),readdir(),closedir()- Directory operationsstat()- File information
- Process Management: Parent-child process relationships
- File Descriptors: Standard input/output/error
- Path Resolution: Finding executables in custom paths
- String Parsing: Tokenizing command-line input
- Error Handling: Proper cleanup and error messages
- No pipe support yet
- No I/O redirection
- No signal handling (Ctrl+C kills entire shell)
- Limited command history
- No tab completion
- Commands must be in
/builddirectory
This is a learning project! Feel free to:
- Add new commands
- Implement planned features
- Fix bugs
- Improve documentation
This project is for educational purposes. Feel free to use and modify.
Built with โค๏ธ to learn systems programming and shell internals.
Note: This shell is a learning project and not intended for production use. For daily work, use bash, zsh, or other mature shells.