0% found this document useful (0 votes)
31 views10 pages

Intro To Vi Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views10 pages

Intro To Vi Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

NOS 110 – OPERATING SYSTEM CONCEPTS

Intro to Vi Lab

Image from O’Reilly vi Editor Referencehttps://www.vim.org/

Objectives
Students will be able to:

• Edit a document using basic vi commands

Reference Information - vi
Before you start, you might want to do some browsing online for good tutorials and reference material.
Remember to bookmark sites you may want to reference again. I’ve provided a few ideas, however, feel
free to look around -- you may find others your like better.

https://www.tutorialspoint.com/unix/unix-vi-editor.htm

http://www.atmos.albany.edu/daes/atmclasses/atm350/vi_cheat_sheet.pdf

O’REILLY is a publishing company that specializes in computer & technology


reference books. Their books are well respected in the industry. The book
cover to the left is from the Learning the vi Editor – Sixth Edition reference.
If you plan to work on UNIX/Linux and use the vi editor, you might want to
look at investing in this book as a good reference.
NOS 110 – OPERATING SYSTEM CONCEPTS

Introduction to vi
Vi comes pre-installed on any/all UNIX/Linux systems. As you’ve read in the Intro to vi Editor document
provided in this lesson, vi has been around “forever” and is often considered archaic and not user-
friendly (difficult). However, it is worth learning the basics of the vi editor just in case you have the need
to use vi in the future. Make sure you follow the directions in this lab carefully.

Lab Requirements
You will not be told how to perform the steps. Refer to previous documentation if you forget how to
perform a particular command. You will not be provided with screen shots for each step of this lab.

You will not have to take screen shots after every command, but you will have to take screen shots at
various spots throughout the tutorial. Some screen shots will require the Host desktop view, one will
not (only Terminal window will be required). Read the instructions carefully, they will specifically state
what needs to be included for each screen shot.

You may want to reference the Intro to vi Editor document and/or the vi Editor “Cheat Sheet”
(referenced above) during this lab. All the commands in this lab are covered in the Intro to vi Editor
document or your textbook.

Instructions
Open a word processing document for pasting your lab answers and screen shots. Save the file as
Lastname-IntroToViLab.docx. Enter the answers for all the lab questions, and copy & paste all screen
shots with the host operating system in the background where requested in the order of the
following activities. Save your file periodically.

1. Start your Ubuntu OS Virtual Machine, and login.

2. Download the woods data file to the Desktop of your Ubuntu VM.

You should be able to use Firefox to download from within your virtual machine to your
Downloads folder, and then copy it to your VM’s Desktop. If so, you can skip over the message on
the next page. If you have trouble downloading from within your virtual machine, follow the
instructions on the next page.
NOS 110 – OPERATING SYSTEM CONCEPTS

IMPORTANT: Starting with Ubuntu Rls 19, VMware Tools only supports drag-and-drop from
your Host to Ubuntu if you drop the file into a Files folder. Follow the steps below:

• From your host computer, download the woods file to your host desktop
• From your Ubuntu VM, open the Files application
• Change to Home directory
• Drag-and-drop woods file from Host to Ubuntu Home folder
• In the Files application click on the Home folder and drag woods to the Desktop folder

Starting with Rls 22 of Ubuntu there are reported idiosyncrasies with Drag and Drop
from host computer to virtual machine. If the above method does not work for you, try
it a couple more times. I found that it usually worked after two or three tries. If it still
doesn’t work, try this method.
• From your virtual machine, open Firefox and go to the Assignments page for this
week.
• Click on the woods (text file)

• Click on the woods file (your file may have a different number from that shown.
Then click on Text Editor and Open

• Save the file to your Home/Desktop folder


NOS 110 – OPERATING SYSTEM CONCEPTS

3. Open a Terminal application window. At the command line, issue the following commands to
perform the actions stated:

• Issue the ls command to list the contents of your current directory. You should not see the
woods file listed.

• Issue the pwd command to see your current directory.

• Issue the cd command to set your working directory to Desktop (remember, the terms
current directory and working directory mean the same thing).

• Issue the ls command to list the contents of your current directory. You should see the
woods file listed.
4. Take a screenshot of your Virtual Machine with your host operating system showing in the
background. Type Step #4 in your document. Paste the screenshot in your Word Document.
Make sure the Ubuntu Desktop is displaying and the Terminal window is visible and shows the
RESULTS for the “ls” command in the Desktop directory. See image below for example.

5. Use the appropriate Linux command to make a backup copy of the woods file on your Desktop.
Name the file woods_backup.
NOS 110 – OPERATING SYSTEM CONCEPTS

SUGGESTION: As you go through this lab, issue any command you feel you need to
in order to verify that your work is correct.

For example, how would you verify the woods_backup file was created
successfully?

If you followed the directions, the woods_backup file should be visible on your
Desktop. If it is not visible, is it behind the Terminal window? (move or minimize
the window)

If you still don’t see it, then you have not followed the directions exactly. Either the
command you used to create the backup did not work, or you were not positioned
in the correct directory. If this is the case, you need to issue various commands to
DEBUG the problem. Perhaps the pwd command, perhaps the ls command.
DEBUGGING is an art, not a science, and sometimes it takes trial-and-error to
determine the source of the problem. In the worst-case scenario, you can always
close your Terminal application window and start the process over.

6. Edit the woods file with the vi editor then issue the vi command that will display line numbers.

7. Take a screenshot of your TERMINAL window. Type Step #7 in your document. Paste the
screenshot in your Word Document. Make sure the Terminal window displays the contents of
the “woods” file WITH LINE NUMBERS clearly visible. See image below for example.
NOS 110 – OPERATING SYSTEM CONCEPTS

8. Take note of the line number on the last line of the file. Delete line 2 (the blank line after the
title of the poem). Notice that the last line number in the file has been decremented by one.
Remember, line numbers are not part of the file, they are virtual numbers. If you add or delete a
line, the line numbers will adjust accordingly.

9. On the 6th line of the file, delete the letter “e” from the word “note”.

10. On the 14th line of the file, correct the spelling of the word “give” by inserting the “i” after the
letter “g”.

11. On the 7th line of the file, replace the word “chipmunks” with “snow”.

12. Remaining in the vi editor, issue the command that will write the file to the Desktop with a name
of woods_some_changes. Before going to the next step, take a screenshot of your Virtual
Machine with your host operating system showing in the background. Type Step #12 in your
document. Paste the screenshot in your Word Document. Make sure the Ubuntu Desktop is
displaying, the Terminal window is displaying and the ICON for the new file
“woods_some_changes” is visible on the Desktop. See image below for example
NOS 110 – OPERATING SYSTEM CONCEPTS

In Microsoft Word, when you save a file to a new name, the document that stays in the foreground is
the document with the new name. Take note of the very bottom of your Terminal window – it should
start with woods_some_changes. This could lead you to believe that you are now working in the new
document. Actually, you are not. Remember, the command Ctrl+g will display the name of the
current file at the bottom of the vi session.

13. Issue the Ctrl+g command to see that the file you are editing is actually still the original woods
file. Take a screenshot of your Virtual Machine with your host operating system showing in the
background. Type Step #13 in your document. Paste the screenshot in your Word Document.
Make sure the Ubuntu Desktop is displaying and the Terminal window is showing the RESULTS
of the “Ctrl+g” command (current “filename”) at the bottom of the vi session. See image below
for example.
NOS 110 – OPERATING SYSTEM CONCEPTS

14. Issue the following command exactly :q If you have already installed VIM (in another lab), note
that you get a warning message indicating that the file has not been saved (see 1st image below).
You saved the file to the new name, but the original file with all of the changes has not yet been
saved.

If you have not already installed VIM, you will be brought back to VI session without a warning
(see second image below)
Take a screenshot of your Virtual Machine with your host operating system showing in the
background. Type Step #14 in your document. Paste the screenshot in your Word Document.
Make sure the Ubuntu Desktop is displaying and the Terminal window is showing the
WARNING message. See images below for example.
NOS 110 – OPERATING SYSTEM CONCEPTS

15. To force the vi edit session to end without saving the changes, issue the command :q!

16. Clear the screen. Use the cat command to view the contents of the woods file. See that the
changes you made above are not in the file.

17. Use the cat command to view the contents of the woods_some_changes file. See that the
changes you made are included in this file.

18. Issue the cp command to copy the woods_some_changes file to the woods file. Note that Linux
does not warn you that you are overwriting an existing file. It just does it!

19. Use vi to edit the woods file. See that the changes you made to the original file are back again.
Issue the command that will display the line numbers.

20. On the 12th line of the file, change the second occurrence of the word “darkest” to “evening”.

21. On the 11th line of the file, delete the second occurrence of the word “the”.

22. On the 21st line of the file, add a comma (“,”) to the end of the line.
23. Save and exit the file.

24. Issue the command to clear the screen.

25. Issue the command to list the contents of the woods file (without editing it).

26. Now, you should have three (3) versions of the file. The original data should be contained in the
file named woods_backup. The woods_some_changes file should contain a version of the file
with the initial set of changes made to it. And, the woods file should contain the file with all the
modifications. Take a screenshot of your Virtual Machine with your host operating system
showing in the background. Type Step #26 in your document. Paste the screenshot in your
Word Document. Make sure the Ubuntu Desktop is displaying, the Terminal window is
displaying and the ICONS for the “woods” “woods_backup” and “woods_some_changes” files
are all visible on the Desktop. See image below for example.
NOS 110 – OPERATING SYSTEM CONCEPTS

27. When you are done submit your Word Document through the assignment page in Blackboard.

28. Save your Lastname-IntroToViLab.docx file. Upload to Blackboard using the assignment link
provided in the lesson.

29. If you are done with your Ubuntu labs, log out and shutdown.

You might also like