Introduction%20to%20Unix%20(CA263)%20%20File%20Editing - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction%20to%20Unix%20(CA263)%20%20File%20Editing

Description:

Computer files containing nothing but printable characters are called text file. ... want to work with a range of lines and refer to the line numbers to specify text ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 27
Provided by: tariq
Category:

less

Transcript and Presenter's Notes

Title: Introduction%20to%20Unix%20(CA263)%20%20File%20Editing


1
Introduction to Unix (CA263) File Editing
  • By
  • Tariq Ibn Aziz

2
Objectives
  • After reading this chapter, you should be able
    to
  • Explain the basics of UNIX/Linux files, including
    ASCII, binary, and executable files
  • Understand the types of editors
  • Create and edit files using the vi editor

3
The Unix Language
  • ASCII, American Standard Code for Information
    Interchange
  • Originally, ASCII used only 7 bits (0 and 1)
    providing 128 characters
  • Extended ASCII uses 8 bits to store 256
    characters. For example English letter H has a
    decimal code 72. In term of bits, H is 01001000

4
ASCII Text Files
  • Computer files containing nothing but printable
    characters are called text file.
  • Files containing nonprintable characters, such as
    machine instructions, are called binary files.
  • Unicode offers up to 65,536 characters.
  • Unicode was developed because 256 character in
    ASCII are not enough to support some languages,
    such as Chinese, that need more than 256
    characters.

5
ASCII Text File
6
USING THE VI EDITOR
  • The vi editor is a modal editor.
  • It works in three mode
  • Insert mode
  • lets you enter text, is accessed by typing the
    letter i
  • Command mode
  • Which is started by pressing Esc
  • Ex mode
  • Employs an extended set of commands that were
    initially used in an early UNIX editor called ex.
  • Press Esc and type () to enter extended command

7
USING THE VI EDITOR
  • Start the vi editor with the e option (vi e
    filename), which places vi exclusively in ex
    mode.
  • To use the vi editor, it is important to master
    the following tasks
  • Creating a file
  • Inserting, editing, and deleting text
  • Searching and replacing text
  • Adding text from other files
  • Copying, cutting, and pasting text
  • Printing a file
  • Saving a file
  • Exiting a file

8
Creating a New File in the vi Editor
  1. Enter vi plus the name of the file you want to
    create, such as vi data.
  2. Press Esc, type w

9
Creating a New File in the vi Editor
  • Another Way to create a file
  • open the vi editor without specifying the file
    name with the vi command
  • You can save the file and specify a file name at
    any time by pressing Esc, typing w filename

10
Using the vi Editor (continued)
To create a new file in the vi editor, type vi
and the name of the new file at the command prompt
11
Inserting Text
  • Before you can insert text in your new file, you
    must use the i (insert) command.
  • In insert mode, every character you type appears
    on the screen.
  • You can return to command mode at any time by
    pressing the Esc key.

12
Repeating a Change
  • When started, the vi editor is in command mode
  • To insert text into a file, you must switch to
    insert mode
  • You can repeat the line just entered with the
    repeat command (.)
  • Note You must press Esc to use (.) to repeat the
    command

13
Moving the Cursor
  • Designers of vi chose the letter keys because of
    their relative position on the keyboard.

14
Deleting Text
  • While still in command mode
  • To delete text, move to a character and then type
    x
  • You can undo a command (reverse its effects) by
    typing u
  • To search for a text pattern, type a forward
    slash (/), type the pattern, and press Enter

15
Searching and Replacing Text
  1. Searching and replacing is a line-oriented
    command that executes independently of the cursor
    position
  2. To find more instances, type n while you are in
    command mode

16
Save File and Exit
  • Saving a file and exiting vi
  • You should always save the file before exiting
    vi, otherwise changes are lost
  • To save a file and continue working on it, type
    the w (write) command
  • While in command mode, use the wq (write and
    quit) command to save and exit iv, or the zz
    command to exit after saving
  • You can also use x to save and exit

17
Save File and Without Exiting
18
Information about file status
  • If you are in an editing session and want to
    review information about the file status, press
    Ctrlg or CtrlG
  • The status line at the bottom of the screen
    displays information, including line-oriented
    commands and error messages.

19
Adding Text from Another File
  • To copy the entire contents of one file into
    another file
  • (1) use the vi editor to edit the file you want
    to copy into and
  • (2) use the command r filename, where filename
    is the name of the file that contains the
    information you want to copy

20
Leaving vi Temporarily
  • If you want to execute other UNIX/Linux commands
    while you work with vi, you can launch a shell or
    execute other commands from within vi.
  • Go to command mode
  • Type !cal (a colon, an exclamation point, and
    the command)
  • press Enter.

21
Using the vi Editor (continued)
  1. Turn on line numbering when you want to work with
    a range of lines and refer to the line numbers to
    specify text
  2. To turn on line numbering, use the set number
    command

22
Copying or Cutting and Pasting
  • You can use the yy command in vi to copy a
    specified number of lines
  • To cut the lines from the file and store them on
    the clipboard, use the dd command.

23
Printing Text Files
  • Sometimes you want to print a file before you
    exit the vi editor.
  • Type !lpr and then type the name of the file you
    want to print.
  • You might have two printers, lp1 and lp2.To print
    the file accounts to lp2, enter !lpr -P lp2
    accounts and press Enter.

24
Canceling an Editing Session
  • You might have to cancel editing session.
  • To cancel session, enter q! and press Enter.

25
Getting Help in vi
  • While you are in vi, press Esc, type !man vi,
    and press Enter
  • Type q and press Enter to go back into your
    editing session.

26
Chapter Summary
  • Bytes are computer characters stored using
    numeric code (e.g., ASCII)
  • The vi editor is a popular choice among
    UNIX/Linux users to edit text files
Write a Comment
User Comments (0)
About PowerShow.com