1 / 26

Introduction to Unix (CA263) File Editing

Introduction to Unix (CA263) File Editing. By Tariq Ibn Aziz. 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.

Download Presentation

Introduction to Unix (CA263) File Editing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 –eoption (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 • Enter viplus the name of the file you want to create, such as vi data. • 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 vicommand • 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 • Searching and replacing is a line-oriented command that executes independently of the cursor position • 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 Ctrl+g or Ctrl+G • 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) • Turn on line numbering when you want to work with a range of lines and refer to the line numbers to specify text • To turn on line numbering, use the :set number command

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

  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 qand 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

More Related