ExNo.3 Simulate UNIX Commands Like CP, LS, Grep, Etc
ExNo.3 Simulate UNIX Commands Like CP, LS, Grep, Etc
#include<stdio.h>
#include<string.h>
void main()
char fn[10],pat[10],temp[200];
FILE *fp;
scanf("%s",fn);
scanf("%s",pat);
fp=fopen(fn,"r");
while(!feof(fp))
fgets(temp,1000,fp);
if(strstr(temp,pat))
printf("%s",temp);
fclose(fp);
}
Output:
pugazh@Pugazh-PC:/mnt/e/ospgm$ gcc grep.c
pugazh@Pugazh-PC:/mnt/e/ospgm$ ./a.out
grep.c
printf
printf("%s",temp);
pugazh@Pugazh-PC:/mnt/e/ospgm$
SIMULATE ls COMMAND USING C
#include<stdio.h>
#include<dirent.h>
main()
char dirname[10];
DIR*p;
scanf("%s",dirname);
p=opendir(dirname);
if(p==NULL)
exit(-1);
while(d=readdir(p))
printf("%s",d->d_name);
}
OUTPUT:
pugazh@Pugazh-PC:/mnt/e/ospgm$ ./a.out
Hello
pugazh@Pugazh-PC:/mnt/e/ospgm$ ./a.out
sam
HillCipher.javaMD5.javaObjectSigningExample.javaplayfair.javaRailFence2.javaRSA.jav
aSHA1.javaVigenereCipher.java
pugazh@Pugazh-PC:/mnt/e/ospgm$
SIMULATE cp COMMAND USING C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
char buffer[1024];
int files[2];
ssize_t count;
if (argc < 3)
return -1;
if (files[0] == -1)
return -1;
if (files[1] == -1)
close(files[0]);
return -1;
OUTPUT: