Laboratory Exercise 5
Laboratory Exercise 5
Laboratory Exercise 5
IT0035L
(APPLIED OPERATING SYSTEMS LABORATORY)
EXERCISE
5
LINUX FILE READERS AND vi EDITOR
Section:
Professor:
Command Description
Creates a new file if it already does not exist, otherwise opens existing
vi filename
file.
vi -R filename Opens an existing file in read only mode.
view filename Opens an existing file in read only mode.
:f filename Renames current file to filename.
Following is the example to create a new file testfile if it already does not exist in the current
working directory:
$vi testfile
As a result you would see a screen something like as follows:
• ~
• ~
• ~
• ~
So now you have opened one file to start with. Before proceeding further let us understanding few
minor but important concepts explained below.
Operation Modes:
While working with vi editor you would come across following two modes:
Command mode: This mode enables you to perform administrative tasks such as saving
files, executing commands, moving the cursor, cutting and pasting lines or words, and
finding and replacing. In this mode, whatever you type is interpreted as a command.
Insert mode: This mode enables you to insert text into the file. Everything that's typed in
this mode is interpreted as input and finally it is put in the file.
The vi always starts in command mode. To enter text, you must be in insert mode. To come in
insert mode you simply type i. To get out of insert mode, press the Esc key, which will put you back
into command mode.
Hint: If you are not sure which mode you are in, press the Esc key twice, and then you'll be in
command mode. You open a file using vi editor and start type some characters and then come in
command mode to understand the difference.
The command to save the contents of the editor is :w. You can combine the above command with
the quit command, or :wq and return.
The easiest way to save your changes and exit out of vi is the ZZ command. When you are in
command mode, type ZZ and it will do the equivalent of :wq.
You can specify a different file name to save to by specifying the name after the :w.
For example, if you wanted to save the file you were working as another filename called filename2,
you would type :w filename2 and return. Try it once.
TASKS:
Part I. How to use vi editor in creating files.
3. Create a directory named Folder1 at your username directory. List the content of Folder1 directory.
Paste your captured executed command and output below.
1. Psalm 23
2. The Lord is my shepherd, I lack nothing.
3. He makes me lie down in green pastures,
4. he leads me beside quiet waters,
5. he refreshes my soul.
6. He guides me along the right paths
7. for his name’s sake.
8. Even though I walk
9. through the darkest valley
10. I will fear no evil,
11. for you are with me;
12. your rod and your staff,
13. they comfort me.
9. In just one line of command, count the number of lines and words are there in Psalm23.txt
Paste your captured executed command and output below.
10. Using vi editor, open your file Psalm23.txt and search for the word Lord in the file content.
Paste your captured executed command and output below.
Observation:
Conclusion:
VII. REFERENCES:
Sobell, M., et al. (2017). A Practical Guide to Linux Commands, Editors, and Shell Programming,
4th Ed. Addison-Wesley Professional