You've just been hired by your local grocery store to stock all the shelves with a delivery that has come in from the warehouse. Congratulations on your new job.
There are a couple of ways you can get these files. Choose the method that works for you. You can click Open
at the top of this page. You could also go to the GitHub link at the top of the lab and, if you are familiar with Github already, clone the repo locally. Otherwise, click on the "Clone or Download" button then the "Download Zip" button on the right side of the screen. Once you've downloaded the file, double click it to unzip the file, and then drag the unzipped file (called 'kwk-l1-advanced-cli') to your development directory.
You've learned about the different commands in your terminal (ls
, mv
, rm
, mkdir
, touch
, etc), but now we're going to learn how to string these commands together by using bash scripting. A bash script is essentially a file with a set of instructions inside of it that when called from the command line will run the commands in the order in which they are written in the file. For example, in your development directory create a file called test_script.sh
. Open this file in the text editor and add the follwing to the contents of the file:
ls;
mkdir this_is_a_directory_made_in_a_script;
mkdir another_directory;
touch this_is_a_directory_made_in_a_script/first_file.txt;
touch this_is_a_directory_made_in_a_script/second_file.txt;
mv this_is_a_directory_made_in_a_script/second_file.txt another_directory
Save and close the file and then run it in your terminal by typing sh test_script.sh
. This will run all the commands in this bash script. From the kwk-l1-advanced-cli
directory, run learn
as usual to check your progress!
Using the mini-lesson above, write a bash script that will put all of the files in the delivery directory in their right locations. As part of the challenge:
- You cannot
cd
into any directories, you must stay in the root directory of the project. - All commands should be written in a shell script called
stock_supermarket.sh
.
The grep
command is awesome. It allows you to search through all the text inside files and returns the line that contains the text you're looking for. For example, create a new file in your development directory called a_lot_of_text.txt
, and then copy and paste all the text from this link. Now, let's say we want to find all instances of the word 'dog'. We'd use the command:
grep dog a_lot_of_text.txt
This will show you all the lines that contain the word 'dog'.
If you want to search the text of many files in many directories, you can use the recursive flag -r
to go through all files in directories within the start directory:
grep -r dog big_directory_with_sub_directories
Using the grep
command, find out the following information:
- What food is otherwise known as gorp?
- Which food has the word grapes in its text file?
- Which food may or may not be gluten free, based on its file text.
- Winston Churchill is hiding in a food's text file. What food?
- What food is used to ward off vampires?
- Name the food that has a joke about canteloupe hidden inside it.
- What food has a youtube link inside of it?
- What food has the word sprinkles in it?
KWK-L1 Advanced Command Line and Shell Scripting