Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Print "hello world".
- # Hint: There are many ways to print text on
- # the command line, one way is with the 'echo'
- # command.
- #
- # Try it below and good luck!
- #
- bash(0)> echo "hello world"
- ===============================================================================================
- # Print the current working directory.
- #
- bash(0)> pwd
- /var/challenges/current_working_directory
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # List names of all the files in the current
- # directory, one file per line.
- #
- bash(0)> ls -l
- total 8
- -rw-r--r--. 1 501 dialout 107 Feb 9 23:35 README
- bash(0)> ls
- README
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print all files in the current directory,
- # one per line (not the path, just the filename)
- # that contain the string "500".
- #
- bash(0)> grep -lir "500" *
- README
- access.log
- access.log.1
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print the last 5 lines of "access.log".
- #
- bash(0)> tail -n 5 access.log
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # There is a file named "access.log" in the
- # current directory. Print the contents.
- #
- bash(0)> cat access.log
- 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
- 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print the relative file paths, one path
- # per line for all filenames that start with
- # "access.log" in the current directory.
- #
- bash(0)> ls a*
- access.log
- access.log.1
- access.log.2
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Delete all of the files in this challenge
- # directory including all subdirectories and
- # their contents.
- #
- bash(0)> ls -A1 | xargs rm -rf
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Count the number of files in the current
- # working directory. Print the number of
- # files as a single integer.
- #
- bash(0)> ls -la
- total 32
- drwxr-xr-x. 2 501 dialout 4096 Jan 29 20:50 .
- drwxr-xr-x. 34 501 dialout 4096 Feb 9 23:33 ..
- -rw-r--r--. 1 501 dialout 145 Feb 9 23:35 README
- -rw-r--r--. 11 501 dialout 901 Jan 9 21:28 access.log
- bash(0)> ls | wc -l
- 2
- ===============================================================================================
- # Print the contents of access.log
- # sorted.
- #
- bash(0)> sort -1
- sort: invalid option -- '1'
- Try 'sort --help' for more information.
- bash(2)> sort access.log
- 101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
- 163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
- 199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
- 200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
- 207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
- 55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print the number of lines
- # in access.log that contain the string
- # "GET".
- #
- bash(0)> grep access.log | wc -l
- 0
- bash(0)> grep "GET" access.log | wc -l
- 8
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # The file split-me.txt contains a list of
- # numbers separated by a ';' character.
- # Split the numbers on the ';' character,
- # one number per line.
- #
- bash(0)> awk -F";" '{for(i=1;i<=$NF;i++) print $i}' split-me.txt
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print the numbers 1 to 100 separated
- # by spaces.
- #
- bash(2)> a=1; for i in {2..100}; do a+=" "$i; done; echo $a
- 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
- 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
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # The file sum-me.txt has a list of numbers,
- # one per line. Print the sum of these numbers.
- #
- bash(0)> cat sum-me.txt
- 1
- 2
- 3
- 5
- 7
- 11
- 13
- bash(0)> acc=0; for i in $(cat sum-me.txt); do acc=$(( $acc+$i )); done; echo $acc
- 42
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # You have a new challenge!
- # Print the lines of the README file in this directory in
- # reverse line order so that the last line is printed first
- # and the first line is printed last.
- # ~~~~~~~~~~~~~~~~~~~~~
- # In the future
- # Environmental destruction will be the norm
- # No longer can it be said that
- # My peers and I care about this earth
- # It will be evident that
- # My generation is apathetic and lethargic
- # It is foolish to presume that
- # There is hope
- # ~~~~~~~~~~~~~~~~~~~~~
- # -Jonathan Reed "The Lost Generation"
- #
- bash(0)> tac README
- #
- # -Jonathan Reed "The Lost Generation"
- # ~~~~~~~~~~~~~~~~~~~~~
- # There is hope
- # It is foolish to presume that
- # My generation is apathetic and lethargic
- # It will be evident that
- # My peers and I care about this earth
- # No longer can it be said that
- # Environmental destruction will be the norm
- # In the future
- # ~~~~~~~~~~~~~~~~~~~~~
- # and the first line is printed last.
- # reverse line order so that the last line is printed first
- # Print the lines of the README file in this directory in
- # **************
- # Reverse the README
- # 👍 👍 👍 Correct!
- # You have a new challenge!
- # Print the file faces.txt, but only print the first instance of each
- # duplicate line, even if the duplicates don't appear next to each other.
- # Note that order matters so don't sort the lines before removing duplicates.
- #
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print the 25th line of the file faces.txt
- #
- bash(0)> sed -n '25~25 p' faces.txt
- ¯\_(ツ)_/¯
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # There are a mix of files in this directory
- # that start with letters and numbers. Print
- # the filenames (just the filenames) of all
- # files that start with a number recursively
- # in the current directory.
- #
- ===============================================================================================
- # The files in this challenge contain spaces.
- # List all of the files (filenames only) in the
- # current directory but replace all spaces with
- # a '.' character.
- #
- bash(0)> ls | sed 's/\s/./g'
- Adam.Simpson
- Alexis.Stein
- Allison.Brown
- Amy.Anderson
- Angel.Saunders
- Brad.Michael
- Briana.Wilson
- Carrie.Alexander
- Christine.Valdez
- Christopher.Miller
- Claudia.Mccormick
- Corey.Bird
- Courtney.Miller
- Crystal.Dunn
- Crystal.Valdez
- Erica.Richardson
- James.Harper
- James.Roberts
- Jared.Hill.DVM
- John.Nguyen
- Jorge.Ross
- Joseph.Hurst
- Karen.Ramirez
- Kevin.Price
- Kimberly.Parker
- Lori.Macias
- Luke.Mason
- Lynn.Robinson
- Mallory.Peterson
- Marie.Gutierrez
- Matthew.Romero
- Michaela.Hobbs
- Molly.Stevens
- Mr..James.Lopez
- Mr..Shawn.Martin
- Mrs..Jade.Clark
- Olivia.Irwin
- Parker.Gilbert
- README
- Robert.Gregory
- Robert.Hill
- Sarah.Hill
- Scott.Rice
- Sheri.Bishop
- Tamara.Anderson
- Tammy.Galloway
- Terri.Young
- Thomas.Parks
- Thomas.Washington
- Tiffany.Clark
- Yvonne.Myers
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Extract all IP addreses from files
- # that start with "access.log" printing one
- # IP address per line.
- #
- bash(0)> find . -name access.* -exec awk '{print $1}' {} \;
- 163.56.115.58
- 75.113.188.234
- 69.16.40.148
- 225.219.54.140
- 207.243.19.2
- 199.37.62.156
- 55.74.240.123
- 251.111.109.143
- 101.163.230.250
- 200.19.168.148
- 108.68.174.15
- 17.2.20.139
- 28.151.137.59
- 199.150.241.179
- 2.71.250.27
- 17.137.186.194
- 151.84.119.34
- 4.180.204.195
- 9.230.96.54
- 157.143.233.21
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print all matching lines (without the filename
- # or the file path) in all files under the current
- # directory that start with "access.log" that
- # contain the string "500". Note that there are no
- # files named "access.log" in the current directory,
- # you will need to search recursively.
- #
- bash(0)> find . -name access.* -exec grep "500" {} \;
- 69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
- 225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
- 2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # There are files in this challenge with
- # different file extensions.
- # Remove all files with the .doc extension
- # recursively in the current working directory.
- #
- bash(0)> find . -name "*.doc" -exec rm {} \;
- ===============================================================================================
- # This challenge has text files (with a .txt extension)
- # that contain the phrase "challenges are difficult".
- # Delete this phrase recursively from all text files.
- # Note that some files are in subdirectories so you will
- # need to search for them.
- #
- bash(0)> find . -name "*.txt" -exec sed -i '/challenges are difficult/ d' {} \;
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # There are a mix of files in this directory
- # that start with letters and numbers. Print
- # the filenames (just the filenames) of all
- # files that start with a number recursively
- # in the current directory.
- #
- bash(0)> ls -pR | grep -e "^[0-9]" | grep -ve "/$"
- 04Carrie Alexander
- 132Rebecca Rubio
- 25Brandon Mcdonald
- 293Linda Bennett
- 335John Joseph
- 388Andrew Carter
- 402Nancy Henson
- 42Robert Hill
- 436Teresa Owens
- 477Thomas Pierce MD
- 48Thomas Allen
- 511Tammy Welch
- 540Katherine Jones
- 593Brett Martin
- 639Charles Ferguson
- 670James Jacobs
- 682Terri Jones
- 737Jeffrey Davis
- 757Robert Marquez
- 778Holly Archer
- 78Michelle Spencer
- 974Michael Bowman
- 3maxime.mp3
- 99blanditiis.avi
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Print all files in the current directory
- # recursively without the leading directory path.
- #
- bash(0)> find -type f -printf %f'\n'
- error.doc
- corporis.xls
- odit.doc
- animi.doc
- necessitatibus.doc
- totam
- beatae.flac
- README
- libero.xls
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # Rename all files removing the extension from
- # them in the current directory recursively.
- #
- ===============================================================================================
- # Print the file faces.txt, but only print the first instance of each
- # duplicate line, even if the duplicates don't appear next to each other.
- # Note that order matters so don't sort the lines before removing duplicates.
- #
- bash(2)> awk '!a[$0]++' faces.txt
- (◕‿◕)
- (^̮^)
- ʘ‿ʘ
- ಠ_ಠ
- ಠ⌣ಠ
- ಠ‿ಠ
- (ʘ‿ʘ)
- (ಠ_ಠ)
- ¯\_(ツ)_/¯
- (ಠ⌣ಠ
- ಠಠ⌣ಠ)
- (ಠ‿ಠ)
- ٩◔̯◔۶
- ヽ༼ຈل͜ຈ༽ノ
- ♥‿♥
- ◔̯◔
- ⊙﹏⊙
- (¬_¬)
- (;一_一)
- (͡° ͜ʖ ͡°)
- (° ͜ʖ °)
- ¯\(°_o)/¯
- ( ゚ヮ゚)
- (︺︹︺)
- # 👍 👍 👍 Correct!
- ===============================================================================================
- # The following excerpt from War and Peace is saved to
- # the file 'war_and_peace.txt':
- #
- # She is betraying us! Russia alone must save Europe.
- # Our gracious sovereign recognizes his high vocation
- # and will be true to it. That is the one thing I have
- # faith in! Our good and wonderful sovereign has to
- # perform the noblest role on earth, and he is so virtuous
- # and noble that God will not forsake him. He will fulfill
- # his vocation and crush the hydra of revolution, which
- # has become more terrible than ever in the person of this
- # murderer and villain!
- #
- # The file however has been corrupted, there are random '!'
- # marks inserted throughout. Print the original text.
- 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