Command-Line-Interpreter is a lightweight, Java-based shell that implements common UNIX-style commands (pwd, cd, ls, mkdir, rmdir, touch, mv, rm, cat), supports output redirection (> and >>), and runs entirely in-process without external dependencies.
- Built-in Commands –
pwd,cd,ls(with-a,-r),mkdir,rmdir,touch,mv,rm,cat - I/O Redirection –
>to overwrite and>>to append output to files - Custom Prompt – Displays the current working directory
- Parser Module – Splits input into a command and arguments
- Graceful Error Handling – Informative messages for invalid usage or missing files/directories
- Unit Tested – Each command has its own JUnit 5 test file
command-line-Interpreter/
├── src/
│ ├── main/
│ │ └── java/
│ │ └── cli/
│ │ ├── Main.java # Entry point, launches Terminal
│ │ ├── Parser.java # Parses raw input into command + args
│ │ └── Terminal.java # Implements built-in commands & interface loop
│ └── test/
│ └── java/
│ └── cli/
│ ├── AppendToAFileTest.java
│ ├── CatTest.java
│ ├── CdTest.java
│ ├── LsTest.java
│ ├── MkdirTest.java
│ ├── MvTest.java
│ ├── PwdTest.java
│ ├── RmTest.java
│ ├── RmdirTest.java
│ ├── TouchTest.java
│ └── WriteToAFileTest.java # Tests for > and >> functionality
├── .gitignore
├── pom.xml # Maven configuration and dependencies
└── README.md # Project documentation
- Language: Java 17
- Build: Maven
- Testing: JUnit 5
- Java 17 or higher
- Maven 3.x
-
Clone the repository
git clone https://github.com/Hemdan47/command-line-Interpreter.git cd command-line-Interpreter -
Build & test
mvn clean verify
-
Run the shell
mvn exec:java -Dexec.mainClass=cli.Main
You’ll see a prompt showing your current working directory, for example:
/home/user/command-line-Interpreter >
- Parser splits the input line on whitespace.
- The first token becomes the command, the rest are arguments.
- Displays the current directory as the prompt.
- Reads a line, invokes
Parser.parse(). - Calls the corresponding method (
pwd(),cd(args),ls(args), etc.). - Handles redirection tokens (
>and>>) by capturing output and writing/appending to files. - Prints command output or error messages.
- pwd – prints the absolute path of the current directory.
- cd [dir] – changes directory; errors on missing, invalid, or non-directory targets.
- ls [-a|-r] – lists files:
- no flag: visible files only
-a: include hidden-r: reverse order
- mkdir [dirs...] – creates one or more directories.
- rmdir [dirs...] – removes empty directories only.
- touch [files...] – creates new empty files.
- mv [src] [dest] – moves or renames files/directories.
- rm [files...] – deletes files only (not directories).
- cat [files...] – prints file contents; errors on directories or missing files.
- >, >> – redirect standard output to a file (overwrite or append).
/home/user/command-line-Interpreter > pwd
/home/user/command-line-Interpreter
/home/user/command-line-Interpreter > ls -a
. .. src pom.xml
/home/user/command-line-Interpreter > mkdir test
/home/user/command-line-Interpreter > cd test
/home/user/command-line-Interpreter/test > touch hello.txt
/home/user/command-line-Interpreter/test > echo "Hello World" > hello.txt
/home/user/command-line-Interpreter/test > cat hello.txt
Hello World
/home/user/command-line-Interpreter/test > exit
- Run tests
mvn test
This project is open source and available under the MIT License.