0% found this document useful (0 votes)
2 views3 pages

Unix Practical Program-stimulate Unix Cmds

The document contains a C program that simulates basic UNIX commands: copy (cp), move (mv), and remove (rm). It prompts the user to choose an operation, takes the necessary file names as input, and performs the corresponding action using standard file operations. The program includes error handling for file operations and provides feedback to the user upon completion of each task.

Uploaded by

mharshi75724
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Unix Practical Program-stimulate Unix Cmds

The document contains a C program that simulates basic UNIX commands: copy (cp), move (mv), and remove (rm). It prompts the user to choose an operation, takes the necessary file names as input, and performs the corresponding action using standard file operations. The program includes error handling for file operations and provides feedback to the user upon completion of each task.

Uploaded by

mharshi75724
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Programs to Simulate UNIX Commands -Simulate cp, mv, and rm

#include <stdio.h>

int main()

int ch;

char src[50], dest[50];

printf("[Link]\[Link]\[Link]\n");

printf("Enter choice: ");

scanf("%d", &ch);
switch(ch)

case 1:

FILE *f1, *f2;

char c;

printf("Source file: ");

scanf("%s", src);

printf("Destination file: ");

scanf("%s", dest);

f1 = fopen(src, "r");

f2 = fopen(dest, "w");

while((c = fgetc(f1)) != EOF)


fputc(c, f2);

fclose(f1);

fclose(f2);

printf("File Copied\n");

break;

case 2:

printf("Old file name: ");


scanf("%s", src);

printf("New file name: ");

scanf("%s", dest); rename(src,

dest); printf("File Moved\n");

break;

case 3:

printf("File name: ");

scanf("%s", src);

remove(src);

printf("File Removed\n");

break;

return 0;
}

Output

[Link]

[Link]

[Link]

Enter choice: 1

Source file: [Link]

Destination file: [Link]

File Copied

You might also like