31
Lesson 2A / Slide 1 of 31 ©NIIT Text Editors Introduction to Linux Pre-Assessment Questions 1. Identify the command that enables you to delete a directory? a. mkdir b. rmdir c. pwd d. cd 2. Angela needs to create a directory called data in her home directory. Identify the command that enables Angela to create a directory in the home directory? a. [Angela@localhost Angela]$ mkdir ~/data b. [Angela@localhost Angela]$ mkdir home data c. [Angela@localhost Angela]$ mkdir data home d. [Angela@localhost Angela]$ mkdir ~/home/data

Pre-Assessment Questions Identify the command that enables you to delete a directory? mkdir rmdir

  • Upload
    karis

  • View
    25

  • Download
    1

Embed Size (px)

DESCRIPTION

Pre-Assessment Questions Identify the command that enables you to delete a directory? mkdir rmdir pwd cd Angela needs to create a directory called data in her home directory. Identify the command that enables Angela to create a directory in the home directory? - PowerPoint PPT Presentation

Citation preview

Page 1: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 1 of 31©NIIT

Text Editors

Introduction to Linux

Pre-Assessment Questions 1. Identify the command that enables you to delete a directory?

a. mkdir

b. rmdir

c. pwd

d. cd

2. Angela needs to create a directory called data in her home directory. Identify the command that enables Angela to create a directory in the home directory?a. [Angela@localhost Angela]$ mkdir ~/data

b. [Angela@localhost Angela]$ mkdir home data

c. [Angela@localhost Angela]$ mkdir data home

d. [Angela@localhost Angela]$ mkdir ~/home/data

Page 2: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 2 of 31©NIIT

Text Editors

Introduction to Linux

Pre-Assessment Questions (Contd.) 3. Identify the command that is used to view the content of a file.

a. cat

b. cp

c. mv

d. rm

4. Identify the command that prompts before deleting a file. a.      rm -fb.      rm -vc.      rm -Rd. rm -i

Page 3: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 3 of 31©NIIT

Text Editors

Introduction to Linux

Pre-Assessment Questions (Contd.) 5. Which of the following commands will change the permission of the file

messages to 000 (----------) from 764 (-rwxrw-r--)? a.     chmod a-rwx messages b.     chmod go-rwx messages c.     chmod ugo+rwx messages d. chmod ugo-rw messages

Page 4: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 4 of 31©NIIT

Text Editors

Introduction to Linux

Solutions to Pre-Assessment Questions 1. b. rmdir2. a. [Angela@localhost Angela]$ mkdir ~/data3. a. cat4. d. rm -i 5. a. chmod a-rwx messages

Page 5: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 5 of 31©NIIT

Text Editors

Introduction to Linux

Objectives

In this lesson, you will learn to:

• Identify functions and types of editors

• Create and modify files in the vi editor using various commands

• Work in emacs and joe editor

• Configure the vi editor

Page 6: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 6 of 31©NIIT

Text Editors

Introduction to Linux

Editors• An editor is application software, which is usually bundled with an operating

system (OS).

• A text editor is used to create and manage text files and documents and has a wide variety of application, such as:

• Creating and maintaining documents

• Writing programs and utilities

• Writing mail messages

• A text editor allows you to perform some basic functions such as:

• Creating a file

• Opening an existing file

• Copying and pasting text

• Searching text

• Handling large amount of data

Page 7: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 7 of 31©NIIT

Text Editors

Introduction to Linux

Editors Available with Linux • There are various editors available with Linux. Some of them are:

• vi (visual editor)

• vim (visual editor improved)

• emacs (edit macros editor)

• sed (stream editor)

• ed (line editor)

• red (restricted ed editor)

• joe (joe’s own editor)

• rjoe (restricted joe editor)

• pico

• jpico (version of the joe editor, which emulates the pico editor used in the Pine mail program)

• jstar (version of the joe editor compatible with WordStar)

Page 8: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 8 of 31©NIIT

Text Editors

Introduction to Linux

The vi Editor• The vi editor:

• Is a visual editor used for creating and editing text files containing data, documents, or programs

• Is a symbolic link to the vim editor in Red Hat and Fedora Core2 Linux

• Is invoked by giving the following command at the Linux prompt: [steve@linuxpc1 steve]$ vi message.txt

• Works in the following three modes:

• Command mode: Enables you to execute the commands that control cursor movement in a file

• Input mode: Enables you to add content in the file that you have created using the vi editor

• Escape mode: Enables you to perform save and substitution operations on a file

Page 9: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 9 of 31©NIIT

Text Editors

Introduction to Linux

The Commands in vi • The following table shows some commonly used commands in vi:

Command Actionh Move cursor to previous characterl Move cursor to next characterk Move cursor up one linej Move cursor down one linex Delete character at current cursor positiondd Delete line:wq<Enter> Save all changes and quit:w<Enter> Save the file:q!<Enter> Quit without saving changes:e <filename><Enter> Open the specified file :w <filename><Enter> Write to a different file:w! <filename><Enter> Force write to another file

:! <command_name><Enter> Execute a shell command

Page 10: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 10 of 31©NIIT

Text Editors

Introduction to Linux

Cursor Movement Commands in vi • The following table shows the basic cursor movement commands:

Command Action

<Ctrl>d or D Scrolls down half screen

<Ctrl>u or U Scrolls up half screen

<Ctrl>F Goes one page forward

<Ctrl>B Goes one page backward

NG Goes to line number n

0 (zero) Goes to the beginning of the line

$ Goes to the end of the line

H Goes to the first line on the screen

M Goes to the middle line on the screen

L Goes to the last line on the screen

z<Enter> Makes the current line the first line on screen

z- Makes the current line the last line on screen

Page 11: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 11 of 31©NIIT

Text Editors

Introduction to Linux

Advanced Reading and Saving Commands

• The following table shows the advanced reading and saving commands:

Command Description

:r file_name Enables you to read another file, file_name, into the current file. The content of the file, file_name, is placed after the cursor position in a new line.

:r !cmd_name Enables you to read the output of cmd_name command into the current file. The output of the command is placed after the cursor position in a new line.

:5,10w file_name Saves lines 5 through 10 of the current file to the file, file_name.

:5,10w >> file_name Appends lines 5 through 10 of the current file to the file, file_name.

Page 12: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 12 of 31©NIIT

Text Editors

Introduction to Linux

Advanced Reading and Saving Commands (Contd.)

• The following table shows the advanced reading and saving commands:

Command Description

:.,$w file_name Saves lines starting from the current cursor position to the end of the file in the file, file_name.

:n file_name Enables you to edit a different file, file_name, which is other then the current file, without exiting the vi editor.

:n# Enables you to edit the previous file if multiple files are open. This command enables you to toggles between two files.

Page 13: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 13 of 31©NIIT

Text Editors

Introduction to Linux

The Insert and Replace Commands • The following table shows the insert and replace commands:

Command Action

a Appends after current character

A Appends at end of line

i Inserts before current character

I Insert at beginning of line

o Inserts blank line below and allows insertion

O Inserts blank line above and allows insertion

rx Replaces current character with character x

Rtext<Esc> Replaces characters with text (until <Esc> is pressed).

Page 14: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 14 of 31©NIIT

Text Editors

Introduction to Linux

The Word Movement Commands

• The following table shows the word movement commands:

Command Action

w Moves to next word

b Moves to previous word

e Moves to end of word

Page 15: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 15 of 31©NIIT

Text Editors

Introduction to Linux

The Deletion and Modification Commands

• The following table shows the deletion and modification commands:Command Action

dw Deletes word

dd Deletes line

cw Changes word

cc Changes line

X Deletes character before current cursor position

J Joins lines

u Undoes last change

U Restores last change

.(dot) Repeats last change

Page 16: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 16 of 31©NIIT

Text Editors

Introduction to Linux

The Commands to Copy Lines • The following table shows the commands to copy lines:

Command Action

yy or Y Yanks or anchors current line, which needs to be copied

Nyy or NY Yanks or anchors N lines, including current line, such as 5yy, which is used when 5 lines are to be copied

p Puts yanked text after current cursor position

P Puts yanked text before current cursor position

Page 17: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 17 of 31©NIIT

Text Editors

Introduction to Linux

The Pattern-Finding Commands

• The following table shows the commands for finding characters or patterns:

Command Action

fx Finds the character x on current line after current cursor position

Fx Finds character x on current line before current cursor position

/pattern <Enter>

Finds next line containing pattern

?pattern <Enter>

Finds previous line containing pattern

Page 18: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 18 of 31©NIIT

Text Editors

Introduction to Linux

Demonstration-Creating Document Using vi

• Problem Statement

• The complaints reported by the customers calling up at the Front Office call center II of Deez Telecommunications Inc. have to be typed in and saved as files. One such customer calls up the Front Office of call center II on September 10, 2004 and reports the following: Hello, I am David Goodman. I have recently purchased a cell phone with a charger set from your company. The invoice number is # 0000818 and the date of purchase is September 07, 2004. My charger set is not functioning properly. It seems to need recharging after every 10 minutes of talk–time and, therefore, my cell phone often dies out during a conversation. My address is #55/99 Sunnyvale St., PA – 828292, and my telephone number is 9632102832. I would like your Support personnel to resolve the problem as soon as possible.

Page 19: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 19 of 31©NIIT

Text Editors

Introduction to Linux

Demonstration-Creating Document Using vi (Contd.)

• Problem Statement (Contd.)

• Angela has been given the task of receiving the calls and typing the details of the complaints as separate files. Angela has recently joined the company. She may require some support in doing this task.

Page 20: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 20 of 31©NIIT

Text Editors

Introduction to Linux

Demonstration-Creating Document Using vi (Contd.)

• Solution

• The following tasks need to be performed:1. Identify the name of the document.2. Identify the command to be used for creating the

document.3. Identify the mode in which the content will be added to

the document.4. Verify the file content.

Page 21: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 21 of 31©NIIT

Text Editors

Introduction to Linux

Demonstration- Editing Document Using vi

• Problem Statement

• The entry details of a customer, David Goodman, are typed incorrectly in the file named Cust_Detail.00001 present under Angela’s home directory. There are also certain spelling errors in the file. Angela needs to resolve the errors in the file to reflect the correct status. The existing content of the file is as follows:

Name : Mr. David Goodman

Mobile Number : 9632102289Addres : # 75 /99 Sunnyvale St. PA - 987613Talk Time Allocted : 100 Hours

Page 22: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 22 of 31©NIIT

Text Editors

Introduction to Linux

Demonstration- Editing Document Using vi (Contd.)

• Problem Statement (Contd.)

• The content to be altered is as follows:

Name : Mr. David Goodman

Mobile Number : 9632102289Address : # 55 /99 Sunnyvale St. PA - 987613Talk Time Allocated : 100 Hours

      

Page 23: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 23 of 31©NIIT

Text Editors

Introduction to Linux

Demonstration-Editing Document Using vi (Contd.)

• Solution

• To edit the document, Angela needs to perform the following tasks: 1. Invoke the vi editor using the identified file name. 2. Edit the document. 3. Save and exit the file. 4. Verify the modifications done on the file.

Page 24: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 24 of 31©NIIT

Text Editors

Introduction to Linux

The emacs and joe Editors

• The emacs editor:

• Is easy to work with because it displays an online Help screen with commonly used commands.

• Enables you to format the source code for several programming languages, such as C and C++.

• Provides a much larger set of commands than the vi editor.

• Is invoked by the following command from the shell prompt: [steve@linuxpc1 steve]$ emacs

• The joe editor:

• Is a full-screen editor.

• Can be invoked by typing joe at the command prompt. You can also give a file name along with the joe command to open the file in the editor.

Page 25: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 25 of 31©NIIT

Text Editors

Introduction to Linux

Configuring vi• The three escape mode commands that change the behavior of the vi editor

are:

• set

• map

• abbr

• The vimrc file:

• Contains the preceding commands to control the behavior of the vi editor .

• Is stored in the /etc directory within the home directory of the user.

• You can use the cat command to view the content of the vimrc file as follows:

$ cat /etc/vimrc

Page 26: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 26 of 31©NIIT

Text Editors

Introduction to Linux

The set Command• The set command:

• Is used to specify the values of the environment variables of the vi editor environment.

• Accepts the vi editor environment variables and their values as parameters and changes the behavior of the editor accordingly. For example, the abbreviation of the :set autowrite command is:

:set aw The following table shows various options of set command:

Options Description

autoindent Specifies that the file content should be automatically indented for easier readability.

ignorecase Activates or deactivates the case sensitivity for the search commands used in the vim editor.

Page 27: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

©NIIT

Text Editors

Introduction to Linux

The set Command (Contd.)The following table shows various options of set command (Contd.):

Options Description

magic Enables the vi editor to treat regular expression characters, such as * and ?, as special characters during the pattern-matching searches.

number Displays line numbers along with the lines displayed in the vi editor.

showmode Displays a message when the vi editor is opened in the input mode

showmatch Enables you to locate matching brackets in the file content.

tabstop=n Defines the tab stop value according to user's choice.

wrapscan Continues pattern search by moving to the beginning of a file so that the entire file is scanned or searched.

Lesson 2A / Slide 27 of 31

Page 28: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 28 of 31©NIIT

Text Editors

Introduction to Linux

The map Command• The map command:

• Is also used to customize the vi editor.

• Has the following syntax::map <the key, which needs mapping> <key

sequence which is to be mapped>

• Is of two types: • :map: Enables you to bind a set of vi commands to a single

keystroke in the command mode. When the mapped keystroke is pressed, it expands to the command sequence.

• Map!: Enables you to map keys in the input mode. As a result, you can press the mapped key while inserting or changing text.

Page 29: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 29 of 31©NIIT

Text Editors

Introduction to Linux

Using the abbreviate Command• The abbreviate command:

• Enables you to define abbreviations for specific strings.

• Has the following syntax::ab <string1> <string2>

• Is used to view the list of abbreviations that you have created using the ab command.

Page 30: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 30 of 31©NIIT

Text Editors

Introduction to Linux

SummaryIn this lesson, you learned:

• An editor is application software used to create and maintain documents.

• Some of the most commonly used editors are:

• vi (visual editor)

• vim (visual editor improved)

• emacs (edit macros editor)

• sed (stream editor)

• ed (line editor)

• red (restricted ed editor)

• joe (Joe’s own editor)

• rjoe (restricted joe editor)

• pico

• jpico

• jstar

Page 31: Pre-Assessment Questions  Identify the command that enables you to delete a directory? mkdir rmdir

Lesson 2A / Slide 31 of 31©NIIT

Text Editors

Introduction to Linux

Summary (Contd.)• The vi editor can be invoked by the vi command.

• The vi editor works in three modes, the insert, command, and escape. The <ESC> key is used to switch between the modes.

• The emacs editor is another very popular editor available on Linux machines.

• You can display the online Help menu in the emacs editor. The emacs editor provides support for spell check and multiple document interfaces.

• The joe editor can be invoked with the joe command.

• You can customize the vi editor to suite your needs by configuring it using the map, set, and abbr commands.