Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* When compiled the program should be saved as execute_me
- *
- * This program teaches the linux command line by having
- * the user move and copy the file among other things.
- *
- * Public Domain - Tnelsond 2011 */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int main(int argc, char * argv[])
- {
- if(!strcmp(*argv, "./execute_me"))
- puts("Ok, so you've executed this program.\nNow change it's name to \"icanchangenames\" by typing: \"mv execute_me icanchangenames\" (without the quotes).\nThe first word after mv (move) is the source and the last one is the destination.\nSo the file gets moved from execute_me to icanchangenames.");
- else if(!strcmp(*argv, "./icanchangenames"))
- {
- FILE *fp = fopen("execute_me", "r");
- if(fp == NULL)
- puts("Great, so you can change names,\nBut can you copy this file and call the copy \"copied\"\n(Hint: use the cp (copy) command)");
- else
- puts("That other file is still there, you didn't move it, you copied!");
- }
- else if(!strcmp(*argv, "./copied"))
- {
- FILE *fp = fopen("icanchangenames", "r");
- if(fp == NULL)
- puts("You didn't copy! You just moved the file");
- else
- puts("So you copied.\nNow mv copied to copied2 and delete the other file.\nDelete the other file using the rm command.\nBut be careful, use rm -i to allow you to confirm deletes.");
- }
- else if(!strcmp(*argv, "./copied2"))
- {
- FILE *fp = fopen("icanchangenames", "r");
- if(fp == NULL)
- {
- puts("Did you delete that other file? (y/n)");
- if(getchar() == 'y')
- puts("Ok, I believe you.\nNow change the name of this file to x.");
- else
- puts("I appreciate your honesty.");
- }
- else
- puts("That other file is still there!");
- }
- else if(!strcmp(*argv, "./x"))
- {
- int x;
- FILE *fp;
- fp = fopen("x", "r");
- fseek(fp, 0, SEEK_END);
- puts("What is the size of this file in bytes?\n(Hint: du -b\nif you don't include the filename of the thing to be measured it will show the size of the whole folder)");
- scanf("%d", &x);
- if(x == ftell(fp))
- puts("Either you are a good guesser or you actually used the command.\nOk, now make a new folder and call it HeLLo. (Use the mkdir command, mkdir is short for make directory).");
- else
- puts("Wrong! Try again");
- }
- else
- puts("Are you sure you spelled everything correctly?\n(Unix-like systems are case sensitive.)");
- return 0;
- }
Add Comment
Please, Sign In to add comment