Guest User

Untitled

a guest
Mar 20th, 2017
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 14.61 KB | None | 0 0
  1. # Print "hello world".
  2. # Hint: There are many ways to print text on
  3. # the command line, one way is with the 'echo'
  4. # command.
  5. #
  6. # Try it below and good luck!
  7. #
  8. bash(0)> echo "hello world"
  9. ===============================================================================================
  10. # Print the current working directory.
  11. #
  12. bash(0)> pwd
  13. /var/challenges/current_working_directory
  14. # 👍 👍 👍  Correct!
  15. ===============================================================================================
  16. # List names of all the files in the current
  17. # directory, one file per line.
  18. #
  19. bash(0)> ls -l
  20. total 8
  21. -rw-r--r--. 1 501 dialout 107 Feb  9 23:35 README
  22. bash(0)> ls
  23. README
  24. # 👍 👍 👍  Correct!
  25. ===============================================================================================
  26. # Print all files in the current directory,
  27. # one per line (not the path, just the filename)
  28. # that contain the string "500".
  29. #
  30. bash(0)> grep -lir "500" *
  31. README
  32. access.log
  33. access.log.1
  34. # 👍 👍 👍  Correct!
  35. ===============================================================================================
  36. # Print the last 5 lines of "access.log".
  37. #
  38. bash(0)> tail -n 5 access.log
  39. 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
  40. 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
  41. 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
  42. 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
  43. 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
  44. # 👍 👍 👍  Correct!
  45. ===============================================================================================
  46. # There is a file named "access.log" in the
  47. # current directory. Print the contents.
  48. #
  49. bash(0)> cat access.log
  50. 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
  51. 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
  52. 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
  53. 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
  54. 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
  55. 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
  56. 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
  57. 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
  58. 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
  59. 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
  60. # 👍 👍 👍  Correct!
  61. ===============================================================================================
  62. # Print the relative file paths, one path
  63. # per line for all filenames that start with
  64. # "access.log" in the current directory.
  65. #
  66. bash(0)> ls a*
  67. access.log
  68. access.log.1
  69. access.log.2
  70. # 👍 👍 👍  Correct!
  71. ===============================================================================================
  72. # Delete all of the files in this challenge
  73. # directory including all subdirectories and
  74. # their contents.
  75. #
  76. bash(0)> ls -A1 | xargs rm -rf
  77. # 👍 👍 👍  Correct!
  78. ===============================================================================================
  79. # Count the number of files in the current
  80. # working directory. Print the number of
  81. # files as a single integer.
  82. #
  83. bash(0)> ls -la
  84. total 32
  85. drwxr-xr-x.  2 501 dialout 4096 Jan 29 20:50 .
  86. drwxr-xr-x. 34 501 dialout 4096 Feb  9 23:33 ..
  87. -rw-r--r--.  1 501 dialout  145 Feb  9 23:35 README
  88. -rw-r--r--. 11 501 dialout  901 Jan  9 21:28 access.log
  89. bash(0)> ls | wc -l
  90. 2
  91. ===============================================================================================
  92. # Print the contents of access.log
  93. # sorted.
  94. #
  95. bash(0)> sort -1
  96. sort: invalid option -- '1'
  97. Try 'sort --help' for more information.
  98. bash(2)> sort access.log
  99. 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
  100. 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
  101. 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
  102. 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
  103. 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
  104. 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
  105. 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
  106. 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
  107. 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
  108. 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
  109. # 👍 👍 👍  Correct!
  110. ===============================================================================================
  111. # Print the number of lines
  112. # in access.log that contain the string
  113. # "GET".
  114. #
  115. bash(0)> grep access.log | wc -l
  116. 0
  117. bash(0)> grep "GET" access.log | wc -l
  118. 8
  119. # 👍 👍 👍  Correct!
  120. ===============================================================================================
  121. # The file split-me.txt contains a list of
  122. # numbers separated by a ';' character.
  123. # Split the numbers on the ';' character,
  124. # one number per line.
  125. #
  126. bash(0)> awk -F";" '{for(i=1;i<=$NF;i++) print $i}' split-me.txt
  127. 1
  128. 2
  129. 3
  130. 4
  131. 5
  132. 6
  133. 7
  134. 8
  135. 9
  136. 10
  137. # 👍 👍 👍  Correct!
  138. ===============================================================================================
  139. # Print the numbers 1 to 100 separated
  140. # by spaces.
  141. #
  142. bash(2)> a=1; for i in {2..100}; do a+=" "$i; done; echo $a
  143. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 5
  144. 7 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  145. # 👍 👍 👍  Correct!
  146. ===============================================================================================
  147. # The file sum-me.txt has a list of numbers,
  148. # one per line. Print the sum of these numbers.
  149. #
  150. bash(0)> cat sum-me.txt
  151. 1
  152. 2
  153. 3
  154. 5
  155. 7
  156. 11
  157. 13
  158. bash(0)> acc=0; for i in $(cat sum-me.txt); do acc=$(( $acc+$i )); done; echo $acc
  159. 42
  160. # 👍 👍 👍  Correct!
  161. ===============================================================================================
  162. # You have a new challenge!
  163. # Print the lines of the README file in this directory in
  164. # reverse line order so that the last line is printed first
  165. # and the first line is printed last.
  166. # ~~~~~~~~~~~~~~~~~~~~~
  167. # In the future
  168. # Environmental destruction will be the norm
  169. # No longer can it be said that
  170. # My peers and I care about this earth
  171. # It will be evident that
  172. # My generation is apathetic and lethargic
  173. # It is foolish to presume that
  174. # There is hope
  175. # ~~~~~~~~~~~~~~~~~~~~~
  176. # -Jonathan Reed "The Lost Generation"
  177. #
  178. bash(0)> tac README
  179. #
  180. # -Jonathan Reed "The Lost Generation"
  181. # ~~~~~~~~~~~~~~~~~~~~~
  182. # There is hope
  183. # It is foolish to presume that
  184. # My generation is apathetic and lethargic
  185. # It will be evident that
  186. # My peers and I care about this earth
  187. # No longer can it be said that
  188. # Environmental destruction will be the norm
  189. # In the future
  190. # ~~~~~~~~~~~~~~~~~~~~~
  191. # and the first line is printed last.
  192. # reverse line order so that the last line is printed first
  193. # Print the lines of the README file in this directory in
  194. # **************
  195. # Reverse the README
  196. # 👍 👍 👍  Correct!
  197. # You have a new challenge!
  198. # Print the file faces.txt, but only print the first instance of each
  199. # duplicate line, even if the duplicates don't appear next to each other.
  200. # Note that order matters so don't sort the lines before removing duplicates.
  201. #
  202. # 👍 👍 👍  Correct!
  203. ===============================================================================================
  204. # Print the 25th line of the file faces.txt
  205. #
  206. bash(0)> sed -n '25~25 p' faces.txt
  207. ¯\_()_/¯
  208. # 👍 👍 👍  Correct!
  209. ===============================================================================================
  210. # There are a mix of files in this directory
  211. # that start with letters and numbers. Print
  212. # the filenames (just the filenames) of all
  213. # files that start with a number recursively
  214. # in the current directory.
  215. #
  216. ===============================================================================================
  217. # The files in this challenge contain spaces.
  218. # List all of the files (filenames only) in the
  219. # current directory but replace all spaces with
  220. # a '.' character.
  221. #
  222. bash(0)> ls | sed 's/\s/./g'
  223. Adam.Simpson
  224. Alexis.Stein
  225. Allison.Brown
  226. Amy.Anderson
  227. Angel.Saunders
  228. Brad.Michael
  229. Briana.Wilson
  230. Carrie.Alexander
  231. Christine.Valdez
  232. Christopher.Miller
  233. Claudia.Mccormick
  234. Corey.Bird
  235. Courtney.Miller
  236. Crystal.Dunn
  237. Crystal.Valdez
  238. Erica.Richardson
  239. James.Harper
  240. James.Roberts
  241. Jared.Hill.DVM
  242. John.Nguyen
  243. Jorge.Ross
  244. Joseph.Hurst
  245. Karen.Ramirez
  246. Kevin.Price
  247. Kimberly.Parker
  248. Lori.Macias
  249. Luke.Mason
  250. Lynn.Robinson
  251. Mallory.Peterson
  252. Marie.Gutierrez
  253. Matthew.Romero
  254. Michaela.Hobbs
  255. Molly.Stevens
  256. Mr..James.Lopez
  257. Mr..Shawn.Martin
  258. Mrs..Jade.Clark
  259. Olivia.Irwin
  260. Parker.Gilbert
  261. README
  262. Robert.Gregory
  263. Robert.Hill
  264. Sarah.Hill
  265. Scott.Rice
  266. Sheri.Bishop
  267. Tamara.Anderson
  268. Tammy.Galloway
  269. Terri.Young
  270. Thomas.Parks
  271. Thomas.Washington
  272. Tiffany.Clark
  273. Yvonne.Myers
  274. # 👍 👍 👍  Correct!
  275. ===============================================================================================
  276. # Extract all IP addreses from files
  277. # that start with "access.log" printing one
  278. # IP address per line.
  279. #
  280. bash(0)> find . -name access.* -exec awk '{print $1}' {} \;
  281. 163.56.115.58
  282. 75.113.188.234
  283. 69.16.40.148
  284. 225.219.54.140
  285. 207.243.19.2
  286. 199.37.62.156
  287. 55.74.240.123
  288. 251.111.109.143
  289. 101.163.230.250
  290. 200.19.168.148
  291. 108.68.174.15
  292. 17.2.20.139
  293. 28.151.137.59
  294. 199.150.241.179
  295. 2.71.250.27
  296. 17.137.186.194
  297. 151.84.119.34
  298. 4.180.204.195
  299. 9.230.96.54
  300. 157.143.233.21
  301. # 👍 👍 👍  Correct!
  302. ===============================================================================================
  303. # Print all matching lines (without the filename
  304. # or the file path) in all files under the current
  305. # directory that start with "access.log" that
  306. # contain the string "500". Note that there are no
  307. # files named "access.log" in the current directory,
  308. # you will need to search recursively.
  309. #
  310. bash(0)> find . -name access.* -exec grep "500" {} \;
  311. 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
  312. 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
  313. 2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
  314. # 👍 👍 👍  Correct!
  315. ===============================================================================================
  316. # There are files in this challenge with
  317. # different file extensions.
  318. # Remove all files with the .doc extension
  319. # recursively in the current working directory.
  320. #
  321. bash(0)> find . -name "*.doc" -exec rm {} \;
  322. ===============================================================================================
  323. # This challenge has text files (with a .txt extension)
  324. # that contain the phrase "challenges are difficult".
  325. # Delete this phrase recursively from all text files.
  326. # Note that some files are in subdirectories so you will
  327. # need to search for them.
  328. #
  329. bash(0)> find . -name "*.txt" -exec sed -i '/challenges are difficult/ d' {} \;
  330. # 👍 👍 👍  Correct!
  331. ===============================================================================================
  332. # There are a mix of files in this directory
  333. # that start with letters and numbers. Print
  334. # the filenames (just the filenames) of all
  335. # files that start with a number recursively
  336. # in the current directory.
  337. #
  338. bash(0)> ls -pR | grep -e "^[0-9]" | grep -ve "/$"
  339. 04Carrie Alexander
  340. 132Rebecca Rubio
  341. 25Brandon Mcdonald
  342. 293Linda Bennett
  343. 335John Joseph
  344. 388Andrew Carter
  345. 402Nancy Henson
  346. 42Robert Hill
  347. 436Teresa Owens
  348. 477Thomas Pierce MD
  349. 48Thomas Allen
  350. 511Tammy Welch
  351. 540Katherine Jones
  352. 593Brett Martin
  353. 639Charles Ferguson
  354. 670James Jacobs
  355. 682Terri Jones
  356. 737Jeffrey Davis
  357. 757Robert Marquez
  358. 778Holly Archer
  359. 78Michelle Spencer
  360. 974Michael Bowman
  361. 3maxime.mp3
  362. 99blanditiis.avi
  363. # 👍 👍 👍  Correct!
  364. ===============================================================================================
  365. # Print all files in the current directory
  366. # recursively without the leading directory path.
  367. #
  368. bash(0)> find -type f -printf %f'\n'
  369. error.doc
  370. corporis.xls
  371. odit.doc
  372. animi.doc
  373. necessitatibus.doc
  374. totam
  375. beatae.flac
  376. README
  377. libero.xls
  378. # 👍 👍 👍  Correct!
  379. ===============================================================================================
  380. # Rename all files removing the extension from
  381. # them in the current directory recursively.
  382. #
  383.  
  384.  
  385. ===============================================================================================
  386. # Print the file faces.txt, but only print the first instance of each
  387. # duplicate line, even if the duplicates don't appear next to each other.
  388. # Note that order matters so don't sort the lines before removing duplicates.
  389. #
  390. bash(2)> awk '!a[$0]++' faces.txt
  391. (◕‿◕)
  392. (^̮^)
  393. ʘ‿ʘ
  394. ಠ_ಠ
  395. ಠ⌣ಠ
  396. ಠ‿ಠ
  397. (ʘ‿ʘ)
  398. (ಠ_ಠ)
  399. ¯\_()_/¯
  400. (ಠ⌣ಠ
  401. ಠಠ⌣ಠ)
  402. (ಠ‿ಠ)
  403. ٩◔̯◔۶
  404. ヽ༼ຈل͜ຈ༽ノ
  405. ♥‿♥
  406. ◔̯◔
  407. ⊙﹏⊙
  408. (¬_¬)
  409. (;一_一)
  410. (͡° ͜ʖ ͡°)
  411. (° ͜ʖ °)
  412. ¯\(°_o)/¯
  413. ( ゚ヮ゚)
  414. (︺︹︺)
  415. # 👍 👍 👍  Correct!
  416. ===============================================================================================
  417. # The following excerpt from War and Peace is saved to
  418. # the file 'war_and_peace.txt':
  419. #
  420. # She is betraying us! Russia alone must save Europe.
  421. # Our gracious sovereign recognizes his high vocation
  422. # and will be true to it. That is the one thing I have
  423. # faith in! Our good and wonderful sovereign has to
  424. # perform the noblest role on earth, and he is so virtuous
  425. # and noble that God will not forsake him. He will fulfill
  426. # his vocation and crush the hydra of revolution, which
  427. # has become more terrible than ever in the person of this
  428. # murderer and villain!
  429. #
  430. # The file however has been corrupted, there are random '!'
  431. # marks inserted throughout.  Print the original text.
  432. bash(0)> sed 's/!//g ;s/betraying us/betraying us!/; s/faith in/faith in!/; s/and villain/and villain!/;' war_and_peace.txt
Advertisement
Add Comment
Please, Sign In to add comment