This repository contains the code and files for the second homework assignment in Operating Systems: Writing Your Own Shell.
Yosi Kariv - 205507460
For any questions or concerns, please reach out to the authors:
- Yosi Kariv: yosikariv@email.com
The project aims to create a custom shell that supports basic functionality such as executing commands, changing directories, and implementing various commands like pwd
, cd
, nano
, cat
, wc
, cp
, clear
, grep
, ls
, executing pipes, and more.
This assignment helps gain experience with advanced programming techniques such as process creation, termination, and overriding an existing process (fork, wait, exec, and additional system calls).
The custom shell supports the following features:
- Print current working directory using
pwd
- Change the working directory using
cd <path>
- Create a file using
cat > <filename>
ornano <filename>
- View the contents of a file using
cat <filename>
- Count words, lines, and characters in a file using
wc [options/flags] <filename>
- Copy files using
cp <file1> <file2>
- Support the pipe operator
|
between processes (only for two commands) - Clear the terminal using
clear
- Return lines with a specific word/string/pattern in a file using
grep [options/flags] [Pattern] <filename>
- List files and directories using
ls [options/flags]
, with support for output redirection, e.g.,ls -l > output_file
- Print all files in the form of a tree structure using
tree
- Terminate the shell process using
exit
- Compile the code using a C compiler like GCC:
gcc main.c -ll
- Run the custom shell executable:
./a.out
- Enter commands as you would in a regular shell, such as
pwd
,cd
,nano
,cat
,wc
,cp
,clear
,grep
,ls
,tree
, and more.
Note: This custom shell has a limited set of features compared to a full-featured shell like Bash or Zsh. The focus of this project is on the implementation of basic shell functionality.
The following functions are some helpful functions for this project:
- fork, exec, execvp, wait, waitpid, dup, pipe, strncmp, strlen, malloc, free, getcwd, chdir, dup2, dup, open, close, readline, gets, fgets, getchar, 'dirent.h', opendir, readdir, closedir.