tnelsond

Learn Linux Command Line

Aug 15th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 KB | None | 0 0
  1. /* When compiled the program should be saved as execute_me
  2.  *
  3.  * This program teaches the linux command line by having
  4.  * the user move and copy the file among other things.
  5.  *
  6.  * Public Domain - Tnelsond 2011 */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11.  
  12. int main(int argc, char * argv[])
  13. {
  14.     if(!strcmp(*argv, "./execute_me"))
  15.         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.");
  16.     else if(!strcmp(*argv, "./icanchangenames"))
  17.     {
  18.         FILE *fp = fopen("execute_me", "r");
  19.         if(fp == NULL)
  20.             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)");
  21.         else
  22.             puts("That other file is still there, you didn't move it, you copied!");
  23.     }
  24.     else if(!strcmp(*argv, "./copied"))
  25.     {
  26.         FILE *fp = fopen("icanchangenames", "r");
  27.         if(fp == NULL)
  28.             puts("You didn't copy! You just moved the file");
  29.         else
  30.             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.");
  31.     }
  32.     else if(!strcmp(*argv, "./copied2"))
  33.     {
  34.         FILE *fp = fopen("icanchangenames", "r");
  35.         if(fp == NULL)
  36.         {
  37.             puts("Did you delete that other file? (y/n)");
  38.             if(getchar() == 'y')
  39.                 puts("Ok, I believe you.\nNow change the name of this file to x.");
  40.             else
  41.                 puts("I appreciate your honesty.");
  42.         }
  43.         else
  44.             puts("That other file is still there!");
  45.  
  46.     }
  47.     else if(!strcmp(*argv, "./x"))
  48.     {
  49.         int x;
  50.         FILE *fp;
  51.         fp = fopen("x", "r");
  52.         fseek(fp, 0, SEEK_END);
  53.         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)");
  54.         scanf("%d", &x);
  55.         if(x == ftell(fp))
  56.             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).");
  57.         else
  58.             puts("Wrong! Try again");
  59.     }
  60.     else
  61.         puts("Are you sure you spelled everything correctly?\n(Unix-like systems are case sensitive.)");
  62.  
  63.     return 0;
  64. }
Add Comment
Please, Sign In to add comment