Introduction to Linux Instructor: Bennett M. Tanyag PART - 2.

Slides:



Advertisements
Similar presentations
In the last Session… ls -l command seven fields nine permissions of a file ls -ld file ownership file permissions (three-tiered file protection system)
Advertisements

In the last class… The vi basics command, input and ex mode Input mode – entering and replacing text Saving text and quitting – the ex mode.
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
A Guide to Unix Using Linux Fourth Edition
Introduction to the gedit editor. gedit: the Gnome editor Gnome: Gnome is a freely available (i.e., no cost) desktop environment for the UNIX system The.
Editing with vi Or more fun than you thought you’d have without a mouse Prof. Chris GauthierDickey.
Program Development Tools IDE vs point tools Two tool flavors exist for developing embedded software: -IDEs: (Integrated Development Environments) i.e.,
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Working Environment - - Linux - -.
Chapter 5 Editing Text Files
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Starting Vi Opening an existing file vi filename Creating a new file vi filename In your workshop directory, create a new file called mysong vi mysong.
CS465 - UNIX The vi Editor. Creating Files Most human-readable files on Unix are created with a text editor Unix has many, many different editors ed a.
Copyrights© 2008 BVU Amplify DITM Basics of OS,UNIX/LINUX and Shell programming Page:1 Lesson 3: Vi- editor By Simi By Simi.
CSCI 330 T HE UNIX S YSTEM Editing files. E DITOR C ONCEPTS Editing a file is to modify the content of a file Text editor: Enter and modify text in a.
Using Linux Text Editors. Use Non-Graphical Linux Text Editors Graphical Text Editor.
Agenda What is Computer Programming? The Programming Process
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Chapter 3 Mastering Editors
MICROSOFT WORD GETTING STARTED WITH WORD. CONTENTS 1.STARTING THE PROGRAMSTARTING THE PROGRAM 2.BASIC TEXT EDITINGBASIC TEXT EDITING 3.SAVING A DOCUMENTSAVING.
Chapter 3: The UNIX Editors ASCII and vi Editors.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving vi Session Aborting Editing Session.
T HE VI EDITOR. vi has 2 modes: command mode (initial or "default" mode) insert mode [Esc] is used to switch to command mode. In general, vi commands:
XP 1 Microsoft Word 2002 Tutorial 1 – Creating a Document.
Software I: Utilities and Internals Lecture 2 – The vi Text Editor * Modified from Dr. Robert Siegfried original presentation.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
UNIX Intro vi  vi is the standard UNIX text editor v Contents 1.Why use vi ? 2. vi Basics 3.Moving Around 4.Inserting Text.
Text editors Why should I use an editor ? It is very important to able to use at least one text mode editor a text mode editor is so useful on remote machines.
Unix Editors. u Editors in Unix come in two general flavours: –modal editors have "modes" v generally input mode and command mode –input mode allows entry.
Tony Kombol.  Why text edit?  Many programs and features require configuration ▪ Configuration is kept in files ▪ Usually in the /etc directory  Changes.
Unix Session IV.
Text Editing February 2 nd, 2004 Class Meeting 3.
1 of 47 Chapter 4: The vi Editor – First Look Copyright ©2008 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
1 © 2012 John Urrutia. All rights reserved. Chapter 6 The vi Editor.
Introduction to Unix (CA263) File Editing By Tariq Ibn Aziz.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Week 8: Linux / ubuntu Dr. I. H. Shah. / CSCS 301 Fall 2009.
Chapter Three The UNIX Editors.
Linux Class #03. File Access Permissions Types of users in Linux: Local User (u) Group User (g) Other User (o) Each User can have 3 types of permissions:
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
THE vi EDITOR. Introduction There are three editors available in almost all versions of Unix: ed, ex and vi. The ed program is the original editor that.
Agenda Using vi Editor Starting vi Session Command / Input Modes Entering Text Editing Text Saving Edited File Aborting Editing Session.
Agenda Using vi Editor Starting vi Session Command / Input Modes
Vi editor Pronounced: `vee eye‘’. Agenda Describe the background of vi Editor Use vi editor to: create text files edit text files Our Goal is to create.
Amir Afzal UNIX Unbounded, 5th Edition Copyright ©2008 Chapter 6: The vi Editor – Last Look 1 of 55 Copyright ©2008 by Pearson Education, Inc. Upper Saddle.
1 Week # 4 Introduction to PDM PDM is a workbench environment that lets programmers and system operators navigate the three levels of the AS/400’s object-based.
BIF703 FTP (File Transfer Protocol) Utility vi editor Utility.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Operating System. What is Operating System OS is system software, which may be viewed as collection of software consisting of procedures for operating.
ITX2000 Remote hosts and web servers Prof. Xiaohong (Sharon) Gao Room: T125 Ext: Week 14 – UNIX vi text editor.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Basic VI Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CS:414 introduction to Unix and Linux
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
Vim basics Vi IMproved.
Guide To UNIX Using Linux Third Edition
Vi Editor.
Unix Fundamentals - Part iii vi Editor
Vim.
Vi Introduction Tony Kombol.
Lecture 3 More on editors: emacs and vi COP 3344 Introduction to UNIX.
Chapter 2 Basic vi Editor.
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
Presentation transcript:

Introduction to Linux Instructor: Bennett M. Tanyag PART - 2

History of vi vi (pronounced “vee eye”) is really the only editor you can find at almost Unix installation. vi stands for visual editor It was originally written at the University of California at Berkeley Versions of vi can found in almost every vendor’s edition of Unix It is initially somewhat hard to get used to, but it has many powerful features.

History of vi Early text editors were line oriented and were typically used from dumb printing terminals. A typical editor that operated in this mode is ed The editor was powerful and efficient, using a very small amount of computer resources, and worked well the display equipment of that time vi offers the user a visual alternative with a significantly expanded command set compared with ed. Vi as we know it today started as the line editor, ex. In fact ex is seen as a special editing mode of vi, although actually the converse is true The visual component of ex can be initiated from the command line by using the vi command, or from within ex.

William Joy developed the ex/vi editor at the University of California at Berkeley. It was originally supplied as an unsupported utility until its official inclusion in the release of AT&T System 5 Unix It has steadily become more popular, in spite of the challenges posed by more modern full screen editors.

vi editor The vi (visual) text editor of UNIX is for creating and editing text files such as letters, memos, reports, correspondences, and the like. vi is a screen-oriented text editor.

There are two modes of operations in vi. 1.The text-edit mode is where the user can enter or edit text. When in the text-edit mode, each the user types a letter, that letter will enter the document the user is editing.

2.The command mode is where the user issues commands to the editor. In this mode, a letter corresponds to a command and not a character to be entered in the text file. For example, in the command mode, the letter h is for moving the cursor one position to the left. When the user types the letter h while in the text-edit mode, it enters the file. Therefore, the user has to be in the command mode in order to perform functions such as moving the cursor (moving around the document), deleting characters, words, or lines, and saving the document.

The format of vi: vi filename(s) Example: $ vi sample.text  Note: If you don’t specify any filename for vi, the filename must be specified later.

Sample vi interface The tilde “~” character indicates unused lines. The last line on the screen is used by the editor for communicating information to the user.

If the file exists, the content of the file will be shown up.

Upon entering the vi editor, the user is automatically taken into the command mode. At this point, the keys on the keyboard represent commands, that is, any character the user types will not enter the file as text but will cause the execution of a certain action.

The cursor in vi is represented by an underscore (underline). In some UNIX versions, the cursor is seen as a box. Once UNIX starts the vi text editor, it places the cursor at the start of the first character of the document.

As the user starts editing the file, the changes are not actually made on the file itself. Everytime vi starts, it copies the file from the disk and into main memory (edit buffer). All editing changes will be made in the edit buffer. The file on the disk remains intact. Changes on the actual document will be made once the user saves the document. In this way, the user may choose to abandon the changes and leave the document as it was.

MOVING IN vi In the command mode, the user may move the cursor anywhere in the document by pressing any of the following keys (no need to press the Enter key):

h or move 1 position to the left l or move 1 position to the right jmove one line down kmove one line up wmove one word to the right bmove one word to the left ^move at the beginning of a line $move at the end of the line # Shift + gmove to line # Ctrl-Fmove forward 1 full page Ctrl-Bmove backward 1 full page Shift + gmove to last line of the document MOVING IN vi

Ctrl-Dmove forward 1/2 page Ctrl-Umove backward 1/2 page -move to the first character of the preceding line Shift + hmove to top of the screen Shift + mmove to the middle of screen Shift + lmove to bottom of the screen MOVING IN vi

If the user types a number before certain commands, it will cause the cursor to move several units. Examples are: 1.Pressing 5h will cause the cursor to move 5 options to the left. 2.Pressing 10k will cause the cursor to move 10 lines up. 3.Pressing 3w will cause the cursor to move 3 words to the right.

DELETING TEXT IN vi While in the command mode, the user may also delete characters, words, or lines. Just move the cursor to the character, word, or line to be deleted and then press the corresponding keys:

CommandAction xdelete one character dwdelete a word dddelete a line Ddelete from the current cursor position to the end of line DELETING TEXT IN vi

If the user types a number before any of these commands, it will cause the deletion of several units. Examples are: 1.Pressing 12x will delete the next 12 characters. 2.Pressing 7dw will delete the next 7 words. 3.Pressing 6dd will delete the next 6 lines. DELETING TEXT IN vi

EDITING TEXT IN vi Command Action iinsert new text before the cursor position Shift + iinsert new text at start of the current line aappend new text after the cursor position Shift + aappend new text at end of current line oopen a new line after the current line Shift + oopen a new line before the cursor position rchange a character (no need to press key afterwards

EDITING TEXT IN vi Shift + roverwrite everything until the key is pressed cwchange word Shift + cchange all text from current cursor position ~convert from upper to lower case and vice versa uundo the last editing change shift + uundo changes in a line.repeat the last editing change shift + jjoin two lines Note: Press the ESC key after making changes.

EXITING vi To exit the vi editor, just simple type a colon ‘:’ (the user should be in the command mode). A colon will appear at the bottom of the screen. At this point, the user can type any of the following (followed by the Enter key):

Command Action q quit vi q!quit vi without saving changes wqsave changes and then quit vi xsame as wq

SAMPLE vi SESSION The text file below contains several errors (line numbers were placed for easy reference):

1 12 Octoer Mr. Linus Torvalds 4 5 Dear Linus Torvalds 6 7 Iam happy to report the successful completion of 8 the UNIX Training Projevt 9 10 Thank you very much Sincerely yours, Bill Gates ~ ~ “sample.text” 15 lines, 203 characters

Making the corrections: 1.To correct the spelling of “October” in line # 1: Just simply put the cursor at the second “o” of the word “October” and press a (append text after current cursor position). The user is now in the text-edit mode. Type b to correct the spelling. Press the ESC key to go back to the command mode. Another option is to place the cursor at “e” and press i (insert new text before the current cursor position).

2.To place the title “President” under “Linus Torvalds” The user should place the cursor at line #3 and press o (open new line after the current line). Since the user is now in the text-edit mode, he can then type the desired text. Then press the ESC key to go back to the command mode. Another option is to place the cursor at line # 4 and press O (open a new line before the current line). The type the required text. Making the corrections:

3.To insert a space in the world “Iam” in line # 7: Place the cursor in “I” and press a. Then insert a space by pressing the Spacebar key. Another option is to place the cursor at “a” and then press i followed by a space. Making the corrections:

4.To correct the spelling of “Projevt” in Line # 8: Place the cursor at “v”. Press x to delete the unwanted character. At this point, the cursor is at “t”. Press i to insert the correct character “c”. Making the corrections:

NOTE:In the vi editor, there is no indication which mode of operation a user is currently in. If he is not sure if vi is in the text-edit or command mode, he should simply press the ESC key and from then on, he is sure that vi is in the command mode.

OTHER FEATURES OF vi Pattern Searching A user may search for any word or string in the file while inside vi. The user should first be in the command mode. Typing a slash “/” will cause the cursor to go to the bottom of the screen. The user may then type in a word or phrase he wants to locate. Pressing the Enter key will cause vi to start searching. If the word or phrase exists, then the cursor will jump to its next occurrence. If the pattern does not exist, then vi will inform the user by showing a message at the bottom of the screen.

Search and Replace To search for a particular word, phrase, or pattern and replace it with another one, type a colon “:” and the cursor will move to the bottom of the screen. Then type %s/old_pattern/new_pattern where old_pattern is the pattern to be replaced while new_pattern is the pattern that will replace old_pattern. OTHER FEATURES OF vi

Block Copy To copy a block of text in vi, first place the cursor at the start of the block (the user should be in the command mode). Then type #yy where # is the number of lines of the block to be copied. Then move the cursor to the position where the block is to be copied and then press p. OTHER FEATURES OF vi

Block Move The procedure for moving blocks of text in vi is the same as with the block copy except that the user should type the command #dd instead of #yy. OTHER FEATURES OF vi

C programming in Linux Linux has a C compiler bundled in the OS. The process to creating a C program is very similar to creating an ordinary C program in other compilers. However, the program should be encoded under vi, then execute the command cc in order to compile the program.

Syntax for cc cc.c Where: cc  command name.c  is the source code of the program. C programming in Linux

Sample program: #include void main(){ printf(“\nC in Linux\n”); } Note: programs should be encoded using the vi editor. C programming in Linux

After you’ve finished encoding the program, you must compile it. The next step would be: $ cc first.c Performing this command will produce a file named a.out. C programming in Linux

The a.out file is the compiled version of your program. To execute the file type this command: $./a.out C in Linux $_ C programming in Linux

Some considerations:  If there are errors encountered in your program, a.out will not be produced.  If a.out exist and errors are encountered a.out will not be updated.  If you compiled another program, a.out will be overridden. (assuming there are no errors) C programming in Linux

Since, a.out is the executable version of your program. It would be advisable to rename a.out to a more descriptive name. For instance, if your program name is compute.c then it would be appropriate to rename a.out to compute.exe (though extension file name does not apply to Linux). C programming in Linux

Try this Create a C program that will ask an integer input from the user. Your program must determine if the number is odd number or an even number. Note: name your file as prog1.c

More on cc Command It would be very tiring to rename a.out every time we compile the program. Recall that we need to rename a.out if we don’t want it to be replaced by other programs when compiling a different source code. $cc prog1.c $mv prog1.c prog1.exe

More on cc Command Another way we can do is using to –o option of cc. The –o option allows you to give an output file name. In this case, instead of a.out to be produced by compiler the filename you specified will be generated. Syntax:  cc prog1.c –o prog1.exe

PRINTING TEXT FILES The lp command in UNIX is the command for printing files. Example: $ lp thesis.doc This will print the file thesis.doc

lp command The lp command does not actually print data; instead, it makes note of the file to be printed. After typing the command, the $ prompt returns immediately, even though nothing has yet printed. In other words, the lp command allows the user to request the printing of a file.

lpsched The lpsched program is the one responsible for printing the files. This program runs in the background and does not interact with the user. The lpsched program is commonly known as the print daemon.

lpsched lpsched will handle multiple print requests on a first come, first served basis. Print jobs will have to wait in a print queue for its turn to be printed.

END OF PART 2 – UNIT 1