Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 2 Dr. Jerry Shiao, Silicon Valley University.

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 8: The vi/vim Editor Chin-Chih Chang
Advertisements

A Guide to Unix Using Linux Fourth Edition
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
Linux+ Guide to Linux Certification, Second Edition
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.
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Ch 71 Using ATTRIB, SUBST, XCOPY, DOSKEY, and the Text Editor.
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.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Introduction to Shell Script Programming
Chapter 3 Mastering Editors
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Basics Chapter 4.
Cmsc 312 Operating Systems. UNIX? DOS – PC? VAX/VMS - mainframe Unix – PC, workstation, mainframe 1970 bell Lab For computer scientist? Why popular? Free.
CENT 305 Information Systems Security Linux Introduction.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
UNIX and Shell Programming (06CS36) Unit 1 Continued… Shrinivas R. Mangalwede Department of Computer Science and Engineering K.L.S. Gogte Institute of.
Introduction to Vim Robbie CSCI2100 Data Structures Tutorial 3.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Editors And Debugging Systems Other System Software Text Editors Interactive Debugging Systems UNIT 5 S.Sharmili Priyadarsini.
Chapter 1 : The Linux System Part 2 Lecture 2 11/14/
4 Editing files and Emacs Editing files The Emacs editor.
Chapter 5 Editing Text Files. Basic Concept A text editor works on a file buffer that is a memory copy of a disk file The disk file is not updated until.
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.
Unix Session IV.
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.
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.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
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.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Chapter 3: Mastering Editors Chapter 3 Mastering Editors (Emacs)
SUSE Linux Enterprise Desktop Administration
Introduction to Shells
Guide To UNIX Using Linux Third Edition
Vi Editor.
Vim.
Text Editors Vim (Chapter 6) Emacs (Chapter 7)
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
The Emacs Editor Read: Forouzan, Appendix C
CSCI The UNIX System Editing files
Presentation transcript:

Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 2 Dr. Jerry Shiao, Silicon Valley University

SILICON VALLEY UNIVERSITY CONFIDENTIAL 2 Summer 2015 Introduction UNIX/Linux Course Section 2 UNIX Shells  UNIX Shells Overview  Shell Programs and Start-up Files  Shell Environment UNIX Editors  vi Editor  emacs Editor

SILICON VALLEY UNIVERSITY CONFIDENTIAL 3 Section 2 UNIX Shells  UNIX Shells UNIX Command Interpreter: Interface between user and the UNIX Kernel.  Shell command can be internal/build-in or external. Internal command: Part of the Shell process.  Builtins implements functionality that cannot be obtained through another script.  Example: cd, break, continue, and exec directly manipulate the shell. Example: history, getopts, kill or pwd more convient as builtin. External command: File ( binary or shell script ) found in $PATH (names of directories searched for external command).  Power of Shell is in its embedded programming language: Shell provides variables, flow control constructs, quoting, functions. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 4 Section 2 UNIX Shells  UNIX bash Shell Builtin Commands Regular Builtin Utilities: Increase the performance of frequently used utilities or to achieve functionality that affects the current environment.  alias, bg, cd, command, false, fc, fg, getopts, jobs, kill, newgrp, pwd, read, true, umask, unalias, wait Special Builtin Utilities: Must be Builtin because of special properties.  break, colon, continue, dot, eval, exec, exit, export, readonly, return, set, shift, times, trap, unset Other BuiltIn Utilities:  bind, builtin, compgen, complete, declare, dirs, disown, echo, enable, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, shopt, source, suspend, test, typeset, ulimit, umask, unalias, wait Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 5 Section 2 UNIX Shells  /usr/sbin: Non-vital System utilities and daemons.  /usr/bin: Programs used by normal users.  /usr/local/sbin: Locally installed sysadmin programs.  /usr/local/bin: Programs locally compiled (not for distribution).  /bin: System utilities required during booting.  /sbin: Sysadmin program needed during booting, before /usr is mounted. Vital system utilities. Pearson Addison-Wesley. $ echo $PATH /usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/ bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/sau/rpi/tools/arm- bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin: /home/sau/bin

SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 Section 2 UNIX Shells Pearson Addison-Wesley. $ ls -l /bin total rwxr-xr-x. 1 root root May bash -rwxr-xr-x. 1 root root Nov cp -rwxr-xr-x. 1 root root Nov ls -rwxr-xr-x. 1 root root Nov mkdir -rwsr-xr-x. 1 root root Oct ping... $ ls -lh /sbin total 14M -rwxr-xr-x. 1 root root 55K Jun arp -rwxr-xr-x. 1 root root 70K Jun ifconfig -rwxr-xr-x. 1 root root 10K Nov insmod -rwxr-xr-x. 1 root root 234K Jun ip...

SILICON VALLEY UNIVERSITY CONFIDENTIAL 7 Section 2 UNIX Shells  Shells Pearson Addison-Wesley. UNIX: Bourne Shell UNIX: Korn Shell UNIX: C Shell Linux: Bash Shell

SILICON VALLEY UNIVERSITY CONFIDENTIAL 8 Section 2 UNIX Shells  ~] echo $SHELL  /bin/bash  ~] sh  sh-3.2$  ~] echo $SHELL  /bin/bash  d Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 9 Section 2 UNIX Shells  Loggin On and Logging Off  Bash Shell Login: /etc/profile Login: Script searched in the following order,  $HOME/.bash_profile  $HOME/.bash_login  $HOME/.profile Shell:  $HOME/.bashrc Logout:  $HOME/.bash_logout Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 10 Section 2 UNIX Shells  Shell Environment Variables Affects the way running processes behave on the computer..profile: Environment variables for the shell and other utilities. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 11 Section 2 UNIX Shells  Shell Metacharacters Characters interpretted with special meaning to the shell. Not letters or digits. Cannot be used in shell commands as literal characters. Cannot be used in naming a file.  Example Common Metacharacters: *, ?, ~, [ ] ~ : Home directory.  cd ~ * : Wild card for many characters. ? : Wild card for one character. [ ] : Specific character or range of characters.  ls lab[0-9]??.* Pearson Addison-Wesley. lab11a.c lab4ab.h

SILICON VALLEY UNIVERSITY CONFIDENTIAL 12 Section 2 UNIX Shells Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 13 Section 2 UNIX Shells Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 14 Section 2 UNIX Editors  UNIX is a text-driven operating system.  Editors in UNIX has GUI, but uses keystroke commands for efficiency and flexibility. Using mouse, GUI input limited by editing input of the GUI.  pico: Pine Composer. Built-in editor for the Pine program. Simple. All commands at bottom of screen.  vi: Visual editor. All features of a word processor and tremendous flexibility in creating text files..exrc: vi evironment file in home directory..vimrc: vi/vim environment file in home directory.  vim: vi Improved. Improved version of vi editor..vimrc: vi/vim environment file in home directory.  emacs: More versatile than word processor, but also more complicated. Multiple windows for executing shell commands and modes for text formatting.  xemacs: Modern graphical user interface support. Icons for editing. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 15 Section 2 UNIX Editors Pearson Addison-Wesley.  Text Editing Functions of Text Editors

SILICON VALLEY UNIVERSITY CONFIDENTIAL 16 Section 2 UNIX Editors  vi editor Features of a word processor. Work buffer is main repository for the file being edited. General purpose buffer for segment of text (i.e. cut or copied). Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 17 Section 2 UNIX Editors  vi editor  Pearson Addison-Wesley. source test.sh total drwxr-xr-x 69 sau users :46. drwxr-xr-x 6 root root :25.. -rw sau users :50.bash_history -rw-r--r-- 1 sau users :35.bashrc -rwxrwxrwx 1 sau users :45 test.sh... sau : :33 (console) sau pts/ :34 sau pts/ :34 sau pts/ :36 sau pts/ :43 /home/sau

SILICON VALLEY UNIVERSITY CONFIDENTIAL 18 Section 2 UNIX Editors  vi editor Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 19 Section 2 UNIX Editors  vi editor  vi Command Mode [#1] operation [#2] target  Execute operation times on target  [#1] = Optional number. Specifying how many operations to be done.  Operation = What to accomplish (i.e. deleting lines of text).  [#2] = How many targets affected.  Target = Text (i.e. line or word of text) to do operation on. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 20 Section 2 UNIX Editors  vi editor  vi Command Mode Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 21 Section 2 UNIX Editors  vi editor  vi Insert/Overlay Mode  Solely for entering text.  Insert Mode places characters in front of the text after the cursor.  Overlay Mode overwrites existing characters after the cursor. aappend text, after the cursor Aappend text, after end of line iinsert text, before the cursor Iinsert text, before first non-whitespace character Renter Overtype Mode oopen new line below cursor in Insert Mode Oopen new line above cursor in Insert Mode Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 22 Section 2 UNIX Editors  vi editor Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 23 Section 2 UNIX Editors  vi editor Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 24 Section 2 UNIX Editors  vi editor  vi Command Mode: Curser Movement and Editing Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 25 Section 2 UNIX Editors Pearson Addison-Wesley. Practice Session 5.4 Step 1: At the shell prompt, type vi firstvi, and then press. Step 2: Type. The cursor moves to the last line of the file. Step 3: Hold down the and keys at the same time. Step 4: Type. A new line opens below the third line of the file. Step 5: Type “This is the 5 th line of a vi file”. Type. Step 6: Type (zero). The cursor moves to the first character of the current line. Step 7: Type. The cursor moves to the last character of the current line. Step 8: Type. A new line opens above the current fourth line. Step 9: Type “This is the 44 th line of a va file”. Type. Step 10: Use the keys to position the cursor over the first 4 in 44 on this line. Step 11: Type. Step 12: Use the keys to position the cursor over the a in va on this line. Step 13: Type and the type. Step 14: Type dd. Step 15: Type :wq to go back to the shell prompt. Step 16: At the shell prompt, type more firstvi and then press. How many lines with text on thnme does more show in this file? This is the first line of a vi file. This is the 2nd line of a vi file. This is the 3rd line of a vi file. This is the 5 th line of a vi file. ~ “firstvi” line 3 of 3 – 100% -- col 1 This is the first line of a vi file. This is the 2nd line of a vi file. This is the 3rd line of a vi file. This is the 44 th line of a va file.  This is the 4 th line of a va file.  This is the 4 th line of a vi file. This is the 5 th line of a vi file. ~ This is the first line of a vi file. This is the 2nd line of a vi file. This is the 3rd line of a vi file. This is the 4 th line of a vi file.  This is the 5 th line of a vi file. This is the 5 th line of a vi file.  ~

SILICON VALLEY UNIVERSITY CONFIDENTIAL 26 Section 2 UNIX Editors  vi editor  vi Command Mode: Yank and Put (Copy and Paste) Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 27 Section 2 UNIX Editors  vi editor  vi Command Mode: Substitute (Search and Replace) : [range] s / old_string / new_string / [ / option ] : = colon prefix for the status line command. range = valid specification of lines in the buffer. If omitted, current line is the range. old_string = text to be replaced. new_string = new text. / = delimiter between the old_string and new_string. / option = modifier, usually for global, to the command. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 28 Section 2 UNIX Editors  vi editor  Setting vi environment Pearson Addison-Wesley. $ cat.exrc set wm=5 shm nu ic $

SILICON VALLEY UNIVERSITY CONFIDENTIAL 29 Section 2 UNIX Editors  vi editor  Executing Shell Commands  : ! Without quitting vi. After execution, returns to Command Mode.  : ! pwd = Displays the pathname of current directory.  : ! ls = Displays the names of all the files in current directory. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 30 Section 2 UNIX Editors  emacs editor Special Text Formatting (i.e. Lisp and C modes of operation). Multiple Windows helps productivity (i.e. windows for editing, executing shell command, executing scripts, handling ). More flexibility and control over text editing. Expense of :  Not intuitive.  More complex keystroke command structure. Uses and prefix characters.  Longer learning curve than vi editor.  emacs [ options ] [ file(s) ] Options:  -n = Begin to edit file(s) starting at line # n.  +nw = Run emacs without opening window. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 31 Section 2 UNIX Editors  emacs editor Pearson Addison-Wesley. A: Name of the current buffer. Name of the file being edited in the window. B: Major and minor mode. Different major modes are used to edit different kind of files (i.e. C programs, Lisp, HTML). C: Percentage of the text shown on-screen. D: Current line number. Location of the cursor in the current buffer. E: Minibuffer. Information and questions/prompts from emacs. F:Speed button bar.Allows quickc common operations graphically. G: Menu bar. Gives a pull-down menus to for all of the important emacs operations. H: Text currently being edited. I: Scroll bar. Graphically scroll or move through the text. J: Status bar.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 32 Section 2 UNIX Editors  emacs editor Pearson Addison-Wesley. Menu Bar: File – Facilities for opening, saving and closing buffers, files, windows, and frames. Edit – Means to modify text in buffers. Options – Facilities to make configuration chagnes. Buffers – A pull-down menu listing of the currently open buffers. Tools – File and application functions. Help – Extensive documentation and on-line manual for emacs. Speed Buttons: Single button presses for (1) file and buffer operations, (2) common text editing operations, such as cut, paste, and (3) printing, searching, and changing preferences.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 33 Section 2 UNIX Editors  emacs editor  Important emacs commands Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 34 Section 2 UNIX Editors  emacs editor  Cursor Movement and Editing Commands Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 35 Section 2 UNIX Editors  emacs editor  Keyboard Macros Collection of keystrokes that can be recorded and then accessed any time. Define multiple keystroke operations as a single command. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 36 Section 2 UNIX Editors  emacs editor Pearson Addison-Wesley. Practice Session 5.7 Step 1:At the shell prompt, type emacs datafile and then press. Step 2: Hold down the and keys on the keyboard at the same time, and then. NOTE: and keys at the same time will cancel the current macro. Step 3: Type and then press. Step 4: Hold down the and keys on the keyboard at the same time, and then. Step 5: Hold down the and keys at the same time and then press the key. Doing so replays the macro that you just defined, placing another line of the numbers 1 – 10 in the buffer. Step 6: Repeat Step 5 eight more times so that there are 10 lines in the buffer. Step 7: Hold down the and keys at the same time and then hold down the and key at the same time. These actions save the buffer to the file datafile. Step 8: Hold down the and keys at the same time and then hold down the and keys at the same time to exit from emacs

SILICON VALLEY UNIVERSITY CONFIDENTIAL 37 Section 2 UNIX Editors  emacs editor  Cut or Copy and Paste Kill Ring – Text is held in a buffer by “killing” it and then restored at another position by yanking it. Region – Mark at one end and move point to the other end. Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 38 Section 2 UNIX Editors  emacs editor  Search and Replace  Replace with prompt: query-replace Console: Query replace: Console: Query replace with : Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 39 Section 2 UNIX Editors  emacs editor  Search and Replace  Replace all occurrances with no prompting: replace-string Console: Replace string: Console: Replace string with: Console: Replaced n occurrences Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 40 Section 2 UNIX Editors  emacs editor  Graphical Editing Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 41 Section 2 UNIX Editors  emacs editor  Graphical Editing Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 42 Section 2 UNIX Editors  emacs editor  Graphical Editing Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 43 Section 2 UNIX Editors  emacs editor  Creating and Editing C Programs Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 44 Section 2 UNIX Editors  emacs editor  Creating and Editing C Programs Pearson Addison-Wesley. Compile choice: C program entered can be compiled, using default options in the C compiler. New window will appear with the the compile command.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 45 Section 2 UNIX Editors  emacs editor  Creating and Editing C Programs Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 46 Section 2 UNIX Editors  emacs editor  Creating and Editing C Programs Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 47 Section 2 UNIX Editors  emacs editor  Working in Multiple Buffers Pearson Addison-Wesley.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 48 Section 2 UNIX Editors  emacs editor  Working in Multiple Buffers Pearson Addison-Wesley.