Guest User

Untitled

a guest
Oct 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. # Excersises for learning bash shell scripting
  2.  
  3. ## Easy
  4.  
  5. #### 1. Create a program that counts the number of files in a directory. It should also check that the argument given is a directory.
  6. Use:
  7.  
  8. `$ ./count foo`
  9.  
  10. Results:
  11.  
  12. `$ foo is not a directory`
  13.  
  14. `$ There are 5 files in foo`
  15.  
  16. #### 2. Create a program that counts the number of files in 2 directories and tells you which has the most. It should also check that the arguments given are directories.
  17.  
  18. Use:
  19. `$ ./count foo bar`
  20.  
  21. Results:
  22.  
  23. `$ foo has the most files (4)`
  24.  
  25. `$ foo and bar both have 3 files`
  26.  
  27. #### 3. Create a program that creates a new executable file with the given name. The script must add executable permission for the user and should add the shebang (#!/bin/bash) to the top line of the file
  28.  
  29. Use:
  30. `$ ./create foo`
  31.  
  32. Results:
  33.  
  34. `$ foo already exists`
  35.  
  36. `$ Success! Executable file foo.sh created`
  37.  
  38. #### 4. Create a script that tells you the difference in length between two files. It should also check that both files exist.
  39.  
  40. Use:
  41. `$ ./check foo bar`
  42.  
  43. Results:
  44.  
  45. `$ file foo does not exist`
  46.  
  47. `$ files foo and bar both have 100 characters`
  48.  
  49. `$ file foo has 23 more characters than file bar`
  50.  
  51. #### 5. Create a script that tells you which file in a directory has the longest name. The script should check the argument is a directory and also that it contains more than 1 file.
  52.  
  53. Use:
  54. `$ ./count foo`
  55.  
  56. Results:
  57.  
  58. `$ foo is not a directory`
  59.  
  60. `$ foo does not contain any files`
  61.  
  62. `$ hello_world.txt has the longest filename in foo`
  63.  
  64. #### 6. Create a script that takes 2 directories and tells you how many filenames of the same name exist in both directories. It should also check that the directories exist and are directories.
  65.  
  66. Use:
  67. `$ ./duplicates foo bar`
  68.  
  69. Results:
  70.  
  71. `$ foo does not exist`
  72.  
  73. `$ bar is not a directory`
  74.  
  75. `$ foo and bar have 4 files in common`
  76.  
  77. #### 7. Create a script that takes a file full of space-separated words and prints the words separated by line, ordered alphabetically. It should also check that the file exists.
  78.  
  79. Use:
  80. `$ ./separate words.txt`
  81.  
  82. Results:
  83. `$ words.txt does not exist`
  84. ```
  85. apple
  86. feather
  87. horse
  88. pinecone
  89. ```
Add Comment
Please, Sign In to add comment