Study Guide for Lab Quiz 3 CHAPTER 5 - 6
Chapter 5 Discovery Exercises
1. Use a command to find the instances in which the word “host” is used in the /etc directory.
Answer: Type grep host /etc/* and press Enter.
2. What addition to the command you used in Exercise 1 can you use to slow the output to one screen at a time? Answer: Add a pipe and use more or less, as in grep host /etc/* | more or grep host /etc/* | less.
3. How can you determine the number of lines and words in the /etc/termcap file? Answer: Type wc -lw /etc/termcap and press Enter.
Note: For students using …show more content…
7. Use a command to compare the trees and more_trees files and show the differences in terms of individual lines that differ.
Answer: Type diff trees more_trees and press Enter.
8. Determine the number of bytes in both the trees and more_trees files using a one-line command.
Answer: Type wc -c trees more_trees and press Enter.
9. Use a command to replace the word “tree” with “plant” in the more_trees file and display the output to the screen.
Answer: Type sed -n s/tree/plant/p more_trees and press Enter.
10. Create a new file, CD_list, and enter these lines in the file: country:1000:210 rock:1001:380 classical:1002:52 alternative:1003:122 light rock:1004:151 light rock:1004:151 celtic:1005:44 jazz:1006:62 soundtracks:1007:32 soundtracks:1007:32
Use the sed command and a script file to add these lines to the end of the CD_list file: hard rock:1008:70 misc:1009:22
Answer: After you create the file CD_list and the script file (see file CD_more file information below) type sed -f CD_more CD_list | cat > CD_list and press Enter.
To create the CD_more file enter vi CD_more and type in the following lines: $a\ hard rock:1008:70\