Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project 3-5. In this hands-on project, you create and edit text files using the vi editor. 1. Switch to a command-line terminal (tty5) by pressing

Project 3-5. In this hands-on project, you create and edit text files using the vi editor.

1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the user name of root and the password of LINUXrocks!.

2. At the command prompt, type pwd , press Enter, and ensure that /root is displayed, showing that you are in the root users home folder. At the command prompt, type vi sample1 and press Enter to open the vi editor and create a new text file called sample1. Notice that this name appears at the bottom of the screen along with the indication that it is a new file.

3. At the command prompt, type My letter and press Enter. Why was nothing displayed on the screen? To switch from command mode to insert mode so you can type text, press i . Notice that the word Insert appears at the bottom of the screen. Next, type My letter and notice that this text is displayed on the screen. What types of tasks can be accomplished in insert mode?

4. Press Esc. Did the cursor move? What mode are you in now? Press two times until the cursor is under the last t in letter. Press the x key. What happened? Next, type i to enter insert mode, then type the letter h . Was the letter h inserted before or after the cursor?

5. Press Esc to switch back to command mode and then move your cursor to the end of the line. Next, type the letter o to open a line underneath the current line and enter insert mode.

6. Type the following:

Notice that the line wraps to the next line partway through the sentence. Though displayed over two lines on the screen, this sentence is treated as one continuous line of text in vi. Press Esc to return to command mode, and then press . Where does the cursor move? Use the cursor keys to navigate to the letter l at the beginning of the word level, and then press the i key to enter insert mode. Press the Enter key while in insert mode. Next, press Esc to return to command mode, and then press . Where does the cursor move?

7. Type dd three times to delete all lines in the file.

8. Type i to enter insert mode, and then type:

and press Enter. Press Enter again. Type:

and press Enter. Type:

and press Enter. Type:

and press Enter. Type:

and press Enter. Press Enter again. Type:

and press Enter. Type:

and press Enter. Type:

and press Enter. Press Enter again. Type:

and press Enter. Type:

and press Enter. Press Enter again. Type:

and press Enter. Type:

and press Enter. You should now have the sample letter used in this chapter on your screen. It should resemble the letter in Figure 3-3.

9. Press Esc to switch to command mode. Next press the Shift+; keys to open the : prompt at the bottom of the screen. At this prompt, type w and press Enter to save the changes you have made to the file. What is displayed at the bottom of the file when you are finished?

10. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type q , and then press Enter to exit the vi editor.

11. At the command prompt, type ls and press Enter to view the contents of your current directory. Notice that there is now a file called sample1 listed.

12. Next, type file sample1 and press Enter. What type of file is sample1? At the command prompt, type cat sample1 and press Enter.

13. At the command prompt, type vi sample1 and press Enter to open the letter again in the vi editor. What is displayed at the bottom of the screen? How does this compare with Step 9?

14. Use the cursor keys to navigate to the bottom of the document. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type !date and press Enter. The current system date and time appear at the bottom of the screen. As indicated, press Enter to return to the document.

15. Press the Shift+; keys again to open the : prompt at the bottom of the screen again, type r !date and press Enter. What happened and why?

16. Use the cursor keys to position your cursor on the line in the document that displays the current date and time, and type yy to copy it to the buffer in memory. Next, use the cursor keys to position your cursor on the first line in the document, and type P (capitalized) to paste the contents of the memory buffer above your current line. Does the original line remain at the bottom of the document?

17. Use the cursor keys to position your cursor on the line at the end of the document that displays the current date and time, and type dd to delete it.

18. Use the cursor keys to position your cursor on the t in the word there on the second line of the file that reads Hi there, I hope this day finds you well., and press dw to delete the word. Next, type i to enter insert mode, type the word Bob , and then press Esc to switch back to command mode.

19. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type w sample2 and press Enter. What happened and why?

20. Press i to enter insert mode, and type the word test. Next, press Esc to switch to command mode. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type q , and press Enter to quit the vi editor. Were you able to quit? Why not?

21. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type q! , and press Enter to quit the vi editor and discard any changes since the last save.

22. At the command prompt, type ls and press Enter to view the contents of your current directory. Notice it now includes a file called sample2, which was created in Step 19. Type diff sample1 sample2 and press Enter to view the difference in content between the two files you created.

23. At the command prompt, type vi sample2 and press Enter to open the letter again in the vi editor.

24. Use the cursor keys to position your cursor on the line that reads Hi Bob, I hope this day finds you well.

25. Press the Shift+; simultaneously to open the : prompt at the bottom of the screen, type s/Bob/Barb/g , and press Enter to change all occurrences of Bob to Barb on the current line.

26. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type 1,$ s/to/TO/g , and press Enter to change all occurrences of the word to to TO for the entire file.

27. Press the u key to undo the last function performed. What happened and why?

28. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type wq , and press Enter to save your document and quit the vi editor.

29. At the command prompt, type vi sample3 and press Enter to open a new file called sample3 in the vi editor. Type i to enter insert mode. Next, type P.S. How were the flies this year? Press the Esc key when finished.

30. Press the Shift+; keys to open the : prompt at the bottom of the screen, type wq , and press Enter to save your document and quit the vi editor.

31. At the command prompt, type vi sample1 , press Enter to open the file sample1 again, and use the cursor keys to position your cursor on the line that reads Mackenzie Elizabeth.

32. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type r sample3 , and press Enter to insert the contents of the file sample3 below your current line.

33. Press the Shift+; keys to open the : prompt at the bottom of the screen, type s/flies/flies and bears/g and press Enter. What happened and why?

34. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type set number , and press Enter to turn on line numbering.

35. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type set nonumber , and press Enter to turn off line numbering.

36. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type set all , and press Enter to view all vi parameters. Press Enter to advance through the list, and press q when finished to return to the vi editor.

37. Press the Shift+; keys to open the : prompt at the bottom of the screen again, type wq , and press Enter to save your document and quit the vi editor.

38. Type exit and press Enter to log out of your shell.

Project 3-6. In this hands-on project, you use the ls command alongside wildcard metacharacters in your shell to explore the contents of your home directory.

1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the user name of root and the password of LINUXrocks!.

2. At the command prompt, type pwd , press Enter, and ensure /root is displayed showing that you are in the root users home folder. At the command prompt, type ls . How many files with a name beginning with the word sample exist in /root?

3. At the command prompt, type ls * and press Enter. What is listed and why?

4. At the command prompt, type ls sample* and press Enter. What is listed and why?

5. At the command prompt, type ls sample? and press Enter. What is listed and why?

6. At the command prompt, type ls sample?? and press Enter. What is listed and why?

7. At the command prompt, type ls sample[13] and press Enter. What is listed and why?

8. At the command prompt, type ls sample[!13] and press Enter. What is listed and why? How does this compare to the results from Step 7?

9. At the command prompt, type ls sample[1-3] and press Enter. What is listed and why?

10. At the command prompt, type ls sample[!1-3] and press Enter. What is listed and why? How does this compare to the results from Step 9?

11. Type exit and press Enter to log out of your shell.

Project 3-7. In this hands-on project, you use the grep and egrep commands alongside regular expression metacharacters to explore the contents of text files.

1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the user name of root and the password of LINUXrocks!.

2. At the command prompt, type grep Inn sample1 and press Enter. What is displayed and why?

3. At the command prompt, type grep -v Inn sample1 and press Enter. What is displayed and why? How does this compare to the results from Step 2?

4. At the command prompt, type grep inn sample1 and press Enter. What is displayed and why?

5. At the command prompt, type grep -i inn sample1 and press Enter. What is displayed and why? How does this compare to the results from Steps 2 and 4?

6. At the command prompt, type grep I sample1 and press Enter. What is displayed and why?

7. At the command prompt, type grep I sample1 and press Enter. What is displayed and why?

8. At the command prompt, type grep t.e sample1 and press Enter. What is displayed and why?

9. At the command prompt, type grep w...e sample1 and press Enter. What is displayed and why?

10. At the command prompt, type grep ^I sample1 and press Enter. What is displayed and why?

11. At the command prompt, type grep ^I sample1 and press Enter. What is displayed and why?

12. At the command prompt, type grep (we|next) sample1 and press Enter. What is displayed? Why?

13. At the command prompt, type egrep (we|next) sample1 and press Enter. What is displayed and why?

14. At the command prompt, type grep Inn$ sample1 and press Enter. What is displayed and why?

15. At the command prompt, type grep ?$ sample1 and press Enter. What is displayed and why? Does the ? metacharacter have special meaning here? Why?

16. At the command prompt, type grep ^$ sample1 and press Enter. Is anything displayed? (Hint: Be certain to look closely!) Can you explain the output?

17. Type exit and press Enter to log out of your shell

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are the specific things I will do to improve my sensitivity?

Answered: 1 week ago

Question

What advice would you provide to Jennifer?

Answered: 1 week ago

Question

What are the issues of concern for each of the affected parties?

Answered: 1 week ago