Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
Labs for A Practical Guide to Linux Commands, Editors, and Shell Programming by Mark G. Sobell

Article: Labs for A Practical Guide to Linux Commands, Editors, and Shell Programming by Mark G. Sobell

Introducing a Few Utilities

In this lab you will learn how to create a simple file using very basic vim editor com-mands and you will also learn how to use a few common utilities. The utilities will be used in their simplest form. Most of the utilities have many options and can be used in many ways. Use the – –help option, or refer to the Command Reference sec-tion of Sobell or to the man page for a utility to learn more about it.

Most of the utilities this lab introduces work with files. Before you can use these util-ities, you must have a file to work with. The first step in this lab explains the basics of how to use the vim editor to create a file.“Chapter 6, Lab 1: Introduction to the vim Editor” on page 22 of this manual explains how to use vim to edit and correct mistakes in files.

  1. The following instructions show how to create a short file. You can correct a mistake on the line you are entering by using the correction keys explained in the previous lab. If you notice a mistake on a previous line, leave it as it is; you will learn how to correct these kinds of mistakes in a later lab.
  2. Give the following command to open thevim editor so it is editing the file named practice.
  • vim practice

The screen will look like Figure 6-1 on page 166 of Sobell.

If bash displays a command not found error, give the preceding command again, replacing vim with vi or vim.tiny.

  1. Before you can insert text into the file you are creating, you must putviminto Input mode. Type the letter i (for Input mode) to put vim into Input mode.
  2. Withvim in Input mode, type a couple of short lines, ending each line with a RETURN. Make sure to end the last line with a RETURN.
  3. Before you can give a command to exit fromvim, you must put vim into Command mode. Press ESCAPE to put vim into Command mode.
  1. Withvim in Command mode, give the command ZZ (type an uppercase Z twice) to write the new file to disk and exit from vim.
  1. In its simplest form, thels utility (Sobell, page 52) lists the names of files in the working directory (Sobell, page 87). After creating a file as explained in step 1, ls will list the name of that file. Use ls to list the names of the files in the working directory.
  • ls practice

When you call ls with an argument (a word following ls and separated from ls by a SPACE), ls displays the name of the file named by the argument or dis-plays an error message if the file does not exist. Call ls with the name of the file created in step 1 and the string xxxx (you must separate each argument from the next by a SPACE). What happens?

  • ls practice xxxx

ls: cannot access xxxx: No such file or directory practice

  1. As opposed tols, which lists the name of a file, the cat utility (Sobell, page 52) displays the contents of a file. Use the cat utility to display the con-tents of the file you just created.
  • cat practice

This is a small text file that I created using a text editor.

  1. Thecp utility (Sobell, page 53) makes a copy of a file. Use cp to make a copy of the file you just created.
  • cp practice practice2
  1. Therm utility (Sobell, page 52) removes (deletes) a file. Use rm to remove the file you created using vim; do not remove the copy of this file you made in the previous step.
  • rm practice
  1. After removing the file you created usingvim, what do ls and cat show when you list the name of and contents of that file?

Because that file no longer exists, ls does not list its name and cat reports that there is no such file; ls does show the copied file.

  1. Theless utility (Sobell, page 53), which was introduced in the previous lab, displays a file one screen at a time. Use the less utility to display a long file, such as /etc/services, one screen at a time and exit from less.
  • less /etc/services..
  • Labs for A Practical Guide to Linux Commands, Editors, and Shell Programming by Mark G. Sobell

Press the SPACE bar to display subsequent screens of text and press q to exit from less.

  1. By default, thehead utility (Sobell, page 57) displays the first 10 lines of a file. Use head to display the first 10 lines of a file such as /etc/services.
  • head /etc/services
  1. By default, thetail utility (Sobell, page 57) displays the last 10 lines of a file. Use tail to display the last 10 lines of a file such as /etc/services.
  • tail /etc/services.
  1. Thehostname utility (Sobell, page 53) displays the name of the system you are working on. Use hostname to display the name of the system you are working on.
  • hostname guava
  1. Themv utility (Sobell, page 53) renames a file. Use mv to rename the copy of the file you made in step 4.
  • mv practice2 practice
  1. Thelpr utility (Sobell, page 55) sends a file to the printer. Use lpr to print the file you renamed in step 11.
  • lpr practice
  1. Thegrep utility (Sobell, page 56) searches for a string of characters in a file. Use grep to display all lines that contain a string (such as small) in the file you renamed in step 11.
  • grep small practice

This is a small text file that I created

  1. Using thevim editor, create a file named days that holds the names of the days of the week, in calendar order. Use cat to display the file.
  • cat days Monday Tuesday Wednesday Thursday Friday Saturday Sunday
  1. Thesort utility (Sobell, page 58) displays a file in alphabetical order. Use sort to display the days file you created in step 14 in alphabetical order.

This lab gives you practice creating files using the vim editor and an understanding of how to use a few common utilities in their simplest forms. When you use script to capture your work in the lab, you can turn the resulting file in to your instructor.

support
close