-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from arora-ansh/newbranch
Added new files
- Loading branch information
Showing
19 changed files
with
1,078 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
run: | ||
gcc ls.c -o ls | ||
gcc cat.c -o cat | ||
gcc date.c -o date | ||
gcc mkdir.c -o mkdir | ||
gcc rm.c -o rm | ||
gcc main.c | ||
clear | ||
./a.out | ||
|
||
clear: | ||
rm ls | ||
rm a.out | ||
rm cat | ||
rm date | ||
rm mkdir | ||
rm rm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//cat command | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <dirent.h> | ||
#include <zconf.h> | ||
|
||
int main(int argc, char **args){ | ||
if(argc==3) { | ||
chdir("/"); | ||
chdir(*(args+2)); | ||
char *line = NULL; | ||
FILE *fptr; | ||
size_t len = 0; | ||
if ((fptr = fopen(*(args + 1), "r")) == NULL) { | ||
printf("No such file or directory\n"); | ||
// Program exits if file pointer returns NULL. | ||
exit(1); | ||
} | ||
|
||
// reads text until newline is encountered | ||
while (getline(&line, &len, fptr) != -1) { | ||
printf("%s", line); | ||
} | ||
fclose(fptr); | ||
} | ||
else if(argc==4){ | ||
if(strcmp(*(args+1),"-n")==0){ | ||
chdir("/"); | ||
chdir(*(args+3)); | ||
char *line = NULL; | ||
FILE *fptr; | ||
size_t len = 0; | ||
if ((fptr = fopen(*(args + 2), "r")) == NULL) { | ||
printf("No such file or directory\n"); | ||
// Program exits if file pointer returns NULL. | ||
exit(1); | ||
} | ||
|
||
// reads text until newline is encountered | ||
int i = 1; | ||
while (getline(&line, &len, fptr) != -1) { | ||
printf("%d %s", i, line); | ||
i++; | ||
} | ||
fclose(fptr); | ||
} | ||
else if(strcmp(*(args+1),"-e")==0){ | ||
chdir("/"); | ||
chdir(*(args+3)); | ||
char *line = NULL; | ||
FILE *fptr; | ||
size_t len = 0; | ||
if ((fptr = fopen(*(args + 2), "r")) == NULL) { | ||
printf("No such file or directory\n"); | ||
// Program exits if file pointer returns NULL. | ||
exit(1); | ||
} | ||
|
||
// reads text until newline is encountered | ||
while (getline(&line, &len, fptr) != -1) { | ||
printf("%s$", line); | ||
} | ||
fclose(fptr); | ||
|
||
} | ||
else{ | ||
printf("Invalid Command, argument required\n"); | ||
} | ||
} | ||
exit(0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//date command | ||
#include <stdio.h> | ||
#include <time.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <dirent.h> | ||
|
||
int main(int argc,char **args) | ||
{ | ||
time_t t = time(NULL); | ||
struct tm tm; | ||
if(argc==1 || (strcmp(*(args+1),"-R")==0)){ | ||
tm = *localtime(&t); | ||
} | ||
else{ | ||
if(strcmp(*(args+1),"-u")==0){ | ||
tm = *gmtime(&t); | ||
} | ||
else{ | ||
printf("Invalid Command, argument required\n"); | ||
exit(0); | ||
} | ||
} | ||
|
||
char month[5]; | ||
char weekday[5]; | ||
if(tm.tm_mon+1==1){ | ||
strcpy(month,"Jan"); | ||
} | ||
if(tm.tm_mon+1==2){ | ||
strcpy(month,"Feb"); | ||
} | ||
if(tm.tm_mon+1==3){ | ||
strcpy(month,"Mar"); | ||
} | ||
if(tm.tm_mon+1==4){ | ||
strcpy(month,"Apr"); | ||
} | ||
if(tm.tm_mon+1==5){ | ||
strcpy(month,"May"); | ||
} | ||
if(tm.tm_mon+1==6){ | ||
strcpy(month,"Jun"); | ||
} | ||
if(tm.tm_mon+1==7){ | ||
strcpy(month,"Jul"); | ||
} | ||
if(tm.tm_mon+1==8){ | ||
strcpy(month,"Aug"); | ||
} | ||
if(tm.tm_mon+1==9){ | ||
strcpy(month,"Sep"); | ||
} | ||
if(tm.tm_mon+1==10){ | ||
strcpy(month,"Oct"); | ||
} | ||
if(tm.tm_mon+1==11){ | ||
strcpy(month,"Nov"); | ||
} | ||
if(tm.tm_mon+1==12){ | ||
strcpy(month,"Dec"); | ||
} | ||
if(tm.tm_wday+1==2){ | ||
strcpy(weekday,"Mon"); | ||
} | ||
if(tm.tm_wday+1==3){ | ||
strcpy(weekday,"Tue"); | ||
} | ||
if(tm.tm_wday+1==4){ | ||
strcpy(weekday,"Wed"); | ||
} | ||
if(tm.tm_wday+1==5){ | ||
strcpy(weekday,"Thu"); | ||
} | ||
if(tm.tm_wday+1==6){ | ||
strcpy(weekday,"Fri"); | ||
} | ||
if(tm.tm_wday+1==7){ | ||
strcpy(weekday,"Sat"); | ||
} | ||
if(tm.tm_wday+1==1){ | ||
strcpy(weekday,"Sun"); | ||
} | ||
|
||
if(argc==1 || (argc==2 && (strcmp(*(args+1),"-R")==0))) { | ||
if(argc==1){ | ||
printf("%s %s %d %02d:%02d:%02d IST %d\n", weekday, month, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, | ||
tm.tm_year + 1900); | ||
} | ||
else{ | ||
printf("%s, %d %s %d %02d:%02d:%02d +0530 \n", weekday, tm.tm_mday, month, tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
} | ||
} | ||
else{ | ||
printf("%s %s %d %02d:%02d:%02d UTC %d\n", weekday, month, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, | ||
tm.tm_year + 1900); | ||
} | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cat: cat [OPTIONS] [ARGS] | ||
Displays the files line by line asked for in the ARGs. | ||
|
||
Flags - | ||
-n Numbers the lines starting from 1 | ||
-e Marks the end of a line using the $ sign |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cd: cd [OPTION] [DIR] | ||
Changes the current directory to given directory, displays an error | ||
if given directory does not exist. | ||
|
||
Flags- | ||
-P Instructs the shell to use the physical directory structure instead | ||
of following symbolic links | ||
--help Displays this help page | ||
|
||
Special Arguments- | ||
.. Takes to the directory prior to current directory | ||
/ Takes to the root directory of the system (if access rights passed) | ||
~ Takes to the home directory of the system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
date: date [OPTIONS] | ||
Displays the present date and time. | ||
|
||
Flags - | ||
-u Displays the present date and time according to UTC. | ||
-R Use RFC 2822 date and time output format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
echo: echo [-neE] [arg ...] | ||
|
||
Output the ARGs. If -n is specified, the trailing newline is | ||
suppressed. | ||
|
||
Flags - | ||
-n Doesn't call a new line after outputting the ARGs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exit: exit | ||
Exits the shell. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
history: history [-c] [-d offset] | ||
Display the history list with line numbers. | ||
|
||
Flags - | ||
-c Clears the previously saved history and then displays the list. | ||
-d offset Removes the entry from history with the given offset and | ||
displays the list. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ls: ls [OPTIONS] | ||
Displays the contents of the current directory. | ||
|
||
Flags - | ||
-A Shows all contents of the directory except . and .. | ||
-m Shows all contents of the directory as seperated by commas | ||
instead of different lines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mkdir: mkdir [OPTIONS] [ARGS] | ||
Makes a directory having the name given in ARGs and default access mode | ||
0777 (rwxrwxrwx). | ||
|
||
Flags - | ||
-v Informs the user wheter a directory was created, shows an error | ||
if it was unable to. | ||
-p Create intermediate directories as required. If this option is | ||
not specified, the full path prefix of each operand must already | ||
exist. On the other hand, with this option specified, no error | ||
will be reported if a directory given as an operand already | ||
exists. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pwd: pwd [-LP] | ||
Print the current working directory. With the -P option, pwd prints | ||
the physical directory, without any symbolic links; the -L option | ||
makes pwd follow symbolic links. | ||
|
||
Flags - | ||
-L Makes pwd show the symbolic positioning of current directory | ||
-P Makes pwd print the current directory's physical positioning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
rm: rm [OPTIONS] [ARGS] | ||
Deletes the files held in ARGs. | ||
|
||
Flags - | ||
-i Asks for the user's permission before deleting a file. | ||
-v Informs the user of the file that is being deleted (verbose). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
history | ||
help pwd | ||
exit | ||
pwd | ||
pwd -L | ||
pwd -P | ||
pwd --help | ||
cd .. | ||
cd A1Shell | ||
cd ~ | ||
cd / | ||
cdcd ~ | ||
cd ~ | ||
exit | ||
cd .. | ||
cd .. | ||
cd CSE231_OS | ||
cd -P | ||
cd -P A1Shell | ||
exit | ||
cd .. | ||
cd .. | ||
cd .. | ||
cd Documents | ||
cd -P c | ||
cd .. | ||
cd .. | ||
cd -P Desktop/CSE231_OS/A1Shell | ||
cd --help | ||
cd --help | ||
help cd | ||
exit | ||
help ls | ||
ls | ||
ls -A | ||
ls -m | ||
help time | ||
hehelp date | ||
help date | ||
date | ||
date -u | ||
date -R | ||
cat Makefile | ||
cat -n Makefile | ||
cat -e Makefile | ||
cd ~ | ||
cd .. | ||
cd .. | ||
cd.. | ||
cd .. | ||
exit | ||
cd ~ | ||
cd Documents/c | ||
ls | ||
rm hello.i | ||
rm -v hello.i | ||
rm -v hello.s | ||
rm -i txtfile.txt | ||
exit | ||
mkdir abc | ||
cd abc | ||
pwd | ||
cd .. | ||
mkdir -v fgh | ||
cd fgh | ||
pwd | ||
cd .. | ||
cd .. | ||
exit | ||
cd .. | ||
cd ~ | ||
cd .. | ||
mkdir -v abc | ||
mkdir -v abcd | ||
cd abcd | ||
pwd | ||
mkdir -p ab/bc/cd | ||
ls | ||
cd ab/bc/cd | ||
pwd | ||
ls | ||
cd ~ | ||
cd // | ||
cd / | ||
cd .. | ||
cd .. | ||
cd .. | ||
cd .. | ||
echo -l | ||
exit | ||
cd .. | ||
../.. | ||
cd ../.. | ||
cd ~ | ||
cd | ||
cd | ||
cd ~ | ||
cd | ||
cd | ||
cd .. | ||
cd / | ||
exit | ||
help cd | ||
help history | ||
history | ||
cd .. | ||
date | ||
pwd | ||
date -u | ||
rm a.out | ||
exit |
Oops, something went wrong.