Lab 3a Using the vi editor

Similar documents
Using echo command in shell script

Lab 5a Shell Script Lab 4 Using Arithmetic Operators in shell script

NETW 110 Lab 3 Post-Installation Configuration Page 1

CHE3935. Lecture 1. Introduction to Linux

Linux Exercise. pwd answer: We call this directory (into which you get when you log in) your home directory.

Getting Started With UNIX Lab Exercises

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Review of Fundamentals

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Editors in Unix come in two general flavours:

Linux/Cygwin Practice Computer Architecture

CS CS Tutorial 2 2 Winter 2018

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Mills HPC Tutorial Series. Linux Basics I

Using the Zoo Workstations

Introduction to Unix and Linux. Workshop 1: Directories and Files

Please choose the best answer. More than one answer might be true, but choose the one that is best.

vi Primer Adapted from:

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Intermediate Programming, Spring Misha Kazhdan

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

CS 143A. Principles of Operating Systems. Instructor : Prof. Anton Burtsev

Getting started with Hugs on Linux

mkdir Phys338 s2017 Draw the tree of the directories and files for this step and all the following cd Phys338 s2017

14. Configuring Telnet in Knoppix

Unix Introduction to UNIX

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Basic Linux Command Line Interface Guide

Open up a terminal, make sure you are in your home directory, and run the command.

PROGRAMMAZIONE I A.A. 2015/2016

AMS 200: Working on Linux/Unix Machines

Introduction to Linux (Part II) BUPT/QMUL 2018/03/21

NETW 110 Lab 5 Creating and Assigning Users and Groups Page 1

Helpful Tips for Labs. CS140, Spring 2015

CENG393 Computer Networks Labwork 1

1. Open VirtualBox and start your linux VM. Boot the machine and log in with the user account you created in Lab #1. Open the Terminal application.

15-122: Principles of Imperative Computation

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Lab #12: Shell Scripting

ITEC451 Network Design & Analysis Laboratory Guide: Appendix

Basic Linux Command Line Interface Guide

vi filename edit filename starting at line 1

FILE MAINTENANCE COMMANDS

CISC 220 fall 2011, set 1: Linux basics

Software I: Utilities and Internals. What is vi?

How to Use This Lab Manual

Session 1: Accessing MUGrid and Command Line Basics

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Introduction: What is Unix?

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

Short Read Sequencing Analysis Workshop

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Topic 2: More Shell Skills

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Linux Shell Script. J. K. Mandal

ELE409 SPRING2018 LAB0

Lab 1 Introduction to UNIX and C

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

The Xemacs Editor. Overview

This tutorial will guide you how to setup and run your own minecraft server on a Linux CentOS 6 in no time.

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Basic vi Commands. What is vi? To Get Into and Out Of vi

Once you have installed MobaXterm, open MobaXterm. Go to Sessions -> New Session, and click on the SSH icon.

Intro to HPC Exercise

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Temple University Computer Science Programming Under the Linux Operating System January 2017

Outline. Structure of a UNIX command

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Enabling SSH on CMS 2.x Server

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo

Introduction to MATLAB

Getting Started with UNIX

Topic 2: More Shell Skills

client X11 Linux workstation

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Introduction to Cygwin Operating Environment

Bok, Jong Soon

RH033 Red Hat Linux Essentials

Intel Edison Tutorial: Introduction to Vim 1

Course 144 Supplementary Materials. UNIX Fundamentals

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

CS Fundamentals of Programming II Fall Very Basic UNIX

Lecture # 2 Introduction to UNIX (Part 2)

There are two tools with which you should be familiar: the program su, and more importantly, sudo. Here we see how to use them.

Using the Vi Text Editor

Getting started with Hugs on Linux

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Operating System Interaction via bash

Transcription:

Lab 3a Using the vi editor Objectives: Become familiar with the vi Editor Review the three vi Modes Review keystrokes to move between vi modes Create a new file with vi Editor Invoke vi with show mode Review the save and quit commands Use editing commands Use search commands Scenario In this lab, the student will use a Linux text-editing tool called the vi (pronounced "vee eye") Editor. This text editor is primarily used for creating and modifying files that customize the work environment and for writing script files to automate tasks. System administrators use text editors to create and modify system files used for networking, security, application sharing, and so on. For users learning to become system administrators, it is important to know how to use the vi Editor. It is sometimes the only full screen editor available to edit crucial system files. Examples of these include scripts and environment control files. Skill in using vi Editor is also needed if the windowing system is not available. The vi Editor is a useful tool when working remotely on other Linux workstations or servers. Administrators routinely login remotely or telnet to another Linux computer to perform maintenance and troubleshooting tasks using the vi Editor. The availability and operation of vi Editor is consistent across all UNIX/Linux platforms. Step 1: Log in to Linux as root and start a terminal window click Application > System Tools > Terminal. Step 2: Launch vi by typing vi studentvi The vi Editor is started from the command line. Whenever invoking vi Editor, the user is opening a file. The name of the file to be created or edited can be specified when the user starts vi Editor, a new file can be opened to be named later. It is common to start vi Editor and specify a file name. If the file exists, it is opened for editing. If the file does not exist, it is created. 1

Review the Three vi Modes There are three modes of operation in vi Editor. Understanding the function of these three modes is the key to working with vi Editor. All commands available with vi Editor can be classified in one of the three modes. Mode Function / Characteristics Command mode Initial default mode for creating and editing files, cursor positioning and modification of existing text. All commands are initiated from this mode. Command Mode: Default mode when vi launch Insert mode Used for entry of new text. Entering an insert command such as I (insert), a (append) and o (open new line) will take the user from command mode to entry mode. Entry commands are stand-alone and are entered without pressing the Enter key. 2

Insert mode> press esc + i press esc again to exit this mode Last-line mode Used for saving work and quitting vi Editor. Type a colon (:) to get to this mode. Pressing the Enter key or Esc key returns to command mode. Last Line mode: press esc + : press esc again to exit this mode 3

Step3: Lets get some hands on Press esc + i to get to the insert mode. Start typing the following: This is line 1 (press enter) This is line 2 (press enter) This is line 3 (press enter) Now press esc and hit enter to get back to the command mode. You will notice you cannot type any text now except to use the arrow key to go between the 3 lines. In order to continue to insert text, use the arrow key to position where you want the text to be and press esc + a and start typing. Use the following example: Press the Esc key to leave Insert Entry mode and return to Command mode. Type esc + : > a colon to go from Command mode to Last-line mode Type a lower case w (write - to save the new file), followed by a lower case q (quit - to exit the vi Editor) and press Enter You will notice that vi has exited and you are back to the terminal prompt now. 4

The new file studentvi should be saved in the practice directory on the hard disk. Display a long listing of this directory to verify that the file is there (ls l). Step 4: Open an Existing File Open studentvi, which was created earlier using the command: vi studentvi. You will notice there are already input that were created from the earlier exercise. Position the cursor at the last line line 5 and press esc + a to append to the line that was typed earlier. Continue to type line 6 and line 7 as shown below. Press the Esc key to leave Insert mode and return to Command mode. Step 5: Use Editing Commands There are a many editing commands that can be used to modify existing text in a file. These include commands for deleting, and changing text. To append text. In the command mode use the arrow key to position the cursor and press esc + a. Delete some text. While in command mode, position the cursor to the desired location and use the options shown in table below to delete some of the mistakes. Note: These commands are ALL lower case and are entered without the Enter key. Basic Text Deletion Commands Command Meaning x Delete character at the cursor dw Delete word (or part of word to right of cursor) 3dw Delete three words dd Delete line containing the cursor 3dd Delete three lines 1. Undo and change some text. To change text and undo changes, use the commands shown in the table below. Many of these commands change the user to Insert mode until Escape is pressed. 5

Note: These commands are ALL lower case. Undo and Change Commands Command Meaning u Undo previous command, try to perform a delete and use the u to undo the action. Now save and exit by pressing esc + : then wq Step6: Remove Files and Directories Created in this Lab At the prompt, type: rm studentvi verify bu issueing the ls l command Instructor Initial 6

Lab 3b> Managing Run Level in Linux Objective Scenario The student will understand the purposes that the Runlevels play in a Linux environment. The system administrator of a large company is responsible for a group of Linux servers whose resources need to be given to the incoming user requests. The systems need to boot up automatically into text mode instead of the GUI mode. The systems resources need to be used for other things besides running the X Window GUI. This task can be accomplished by permanently changing the default runlevel. Manually change the Runlevel Manually change the runlevel using the following steps: 1. log in as root 2. Make sure that the system is booted and that the X Window GUI is running. 3. Open a terminal window and type init 3 or /sbin/init 3 at the command prompt. The system should exit the GUI mode and take a few seconds to terminate some running processes. Then, the system will enter text mode. 4. Once the login prompt appears, log back in as the root user. 5. After successfully logged on, type init 5 or /sbin/init 5 at the shell prompt. 6. The GUI login interface will now load. Log in to the X Window session again with the root account. The runlevel has been successfully changed. Instructor s Initial 7

Permanently Changing the Runlevel It is a simple process to permanently change the default runlevel on a Linux system: 7. Open a terminal window, then open the /etc/inittab file with the vi editor. To do this enter vi /etc/inittab at the shell prompt. Read over this file. It contains a lot of useful information regarding the system configuration. 8. Change the default runlevel manually so the system will automatically start in text mode instead of GUI mode. To permanently change the default runlevel, change the id:5:initdefault: line to id:3:initdefault:. 9. Save this edit. To save, press the Esc key on the keyboard, then type :wq and press Enter. This should return the system to a shell prompt. 10. Verify the effect by typing shutdown r now 11. The Linux system will boot up in text mode. Log in as root and at the prompt, type init 5 to switch back to the GUI mode. 12. Repeat step 7 to 9 but this time change the id:3:initdefault: line to id:5:initdefault:. 13. Verify the effect by repeating step 10. Once system restart, log in as root. Instructor s Initial 8

Lab 3c Shell Script Lab 1 Writing the first shell script Objective Upon completion of this lab, the student will be able to create a simple shell script file and run it in the Linux environment Scenario The student is the administrator of a Linux server who wants to create a simple shell script to test whether it is able to run in Linux OS. Procedures Login into Fedora operating system. Use a text editor such as gedit, vi or emacs. Write required Linux commands and logic in the file. Save and close the file (exit from gedit, vi or emacs). Make the script executable. Test the script by running it, and verify the output. Step 1: Creating the Script 1. Login into Fedora operating system. 2. Launch gedit Text Editor by clicking on Applications Accessories gedit Text Editor 9

3. Type in the following using gedit text editor: #!/bin/bash echo "Hello, World!" echo "Knowledge is power." 4. Save the text by clicking on File Save As 10

5. Type in hello.sh as the name of the file. Make sure the file is saved in the home directory of the login user account. Close the file after saving. Step 2: Running the Script 11

1. Go to terminal by click on Application System Tools Terminal 2. At the terminal, you can run the script by typing as follows:./hello.sh Sample outputs: The command./hello.sh displayed an error message on the screen. It will not run script since you've not set execute permission for your script hello.sh. 3. Make the script executable by typing as follows: chmod +x hello.sh 4. To execute this program, type the following command:./hello.sh Sample Outputs: 12

Reflection: 1) What is one purpose of using shell script? 2) What is the purpose of using echo command? 3) What is another method to run the script without making it executable? 13