OS Lab - Record
OS Lab - Record
DATE:
EX.NO: 2b
STUDY OF SHELL PROGRAMMING
AIM:
Algorithm:
1. Start
2. Read two number from user
3. Add the given two numbers.
4. Print the result
5. Stop
Code:
RESULT:
The study of shell programming was conducted and the programs were
successfully executed .
AIM:
To implement unix commands such as copy, move, grep and ls in the C langauge.
(i) Copy:
Code:
#include <stdio.h>
#include<stdlib.h>
void main ()
{
FILE *fp1,*fp2;
fp1=fopen(“file1”,”r”);
fp2=fopen(“file5”,”w”);
char s[100];
fgets(s,100,fp1);
while(!feof (fp1))
{
fputs(s,fp2);
fgets(s,100,fp1);
}
fclose(fp1);
fclose(fp2);
}
Sample output:
file 1 file 5
cat1 cat1
cat2 cat2
dog1 dog1
ROLL NO:2127230501158 Page |
(ii) Move
Code:
#include <stdio.h>
#include<stdlib.h>
void main ()
{
FILE *fp1,*fp2;
fp1=fopen(“file1”,”r”);
fp2=fopen(“file5”,”w”);
char s[100];
fgets(s,100,fp1);
while(!feof (fp1))
{
fputs(s,fp2);
fgets(s,100,fp1);
}
remove(“file1”);
fclose(fp1);
fclose(fp2);
}
Sample output:
file 1 file 5
<empty file> cat1
cat2
dog1
#include<stdio.h>
#include<dirent.h>
void main()
{
DIR *D;
struct dirent *r;
d=opendir(“Sample”);
r=readdir(d);
while (r!=NULL)
{
printf(“%s”,r→d_name);
r=readdir(d);
}
}
OUTPUT
f3 ..f2.f1
RESULT:
Thus we have implemented unix commands such as copy, move, grep and ls in the C
langauge.