Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to UNIX / Linux - 2 Dr. Jerry Shiao, Silicon Valley University."— Presentation transcript:

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

2 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

3 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. Copyright @2005 Pearson Addison-Wesley.

4 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 Copyright @2005 Pearson Addison-Wesley.

5 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. Copyright @2005 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

6 SILICON VALLEY UNIVERSITY CONFIDENTIAL 6 Section 2 UNIX Shells Copyright @2005 Pearson Addison-Wesley. $ ls -l /bin total 7528 -rwxr-xr-x. 1 root root 877480 May 21 2010 bash -rwxr-xr-x. 1 root root 123356 Nov 3 2010 cp -rwxr-xr-x. 1 root root 118832 Nov 3 2010 ls -rwxr-xr-x. 1 root root 46680 Nov 3 2010 mkdir -rwsr-xr-x. 1 root root 42136 Oct 12 2010 ping... $ ls -lh /sbin total 14M -rwxr-xr-x. 1 root root 55K Jun 14 2010 arp -rwxr-xr-x. 1 root root 70K Jun 14 2010 ifconfig -rwxr-xr-x. 1 root root 10K Nov 25 2009 insmod -rwxr-xr-x. 1 root root 234K Jun 2 2011 ip...

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

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

9 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 Copyright @2005 Pearson Addison-Wesley.

10 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. Copyright @2005 Pearson Addison-Wesley.

11 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]??.* Copyright @2005 Pearson Addison-Wesley. lab11a.c lab4ab.h

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

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

14 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 email 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. Copyright @2005 Pearson Addison-Wesley.

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

16 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). Copyright @2005 Pearson Addison-Wesley.

17 SILICON VALLEY UNIVERSITY CONFIDENTIAL 17 Section 2 UNIX Editors  vi editor  Copyright @2005 Pearson Addison-Wesley. sau@buildbed-vm:~> source test.sh total 15368 drwxr-xr-x 69 sau users 4096 2012-09-19 00:46. drwxr-xr-x 6 root root 4096 2012-04-03 02:25.. -rw------- 1 sau users 24900 2012-09-18 18:50.bash_history -rw-r--r-- 1 sau users 1177 2011-02-18 14:35.bashrc -rwxrwxrwx 1 sau users 16 2012-09-19 00:45 test.sh... sau :0 2012-09-18 10:33 (console) sau pts/1 2012-09-18 10:34 sau pts/0 2012-09-18 10:34 sau pts/3 2012-09-18 10:36 sau pts/6 2012-09-18 22:43 /home/sau

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

19 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. Copyright @2005 Pearson Addison-Wesley.

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

21 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 Copyright @2005 Pearson Addison-Wesley.

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

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

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

25 SILICON VALLEY UNIVERSITY CONFIDENTIAL 25 Section 2 UNIX Editors Copyright @2005 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.  ~

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

27 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. Copyright @2005 Pearson Addison-Wesley.

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

29 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. Copyright @2005 Pearson Addison-Wesley.

30 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 email). 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. Copyright @2005 Pearson Addison-Wesley.

31 SILICON VALLEY UNIVERSITY CONFIDENTIAL 31 Section 2 UNIX Editors  emacs editor Copyright @2005 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.

32 SILICON VALLEY UNIVERSITY CONFIDENTIAL 32 Section 2 UNIX Editors  emacs editor Copyright @2005 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.

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

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

35 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. Copyright @2005 Pearson Addison-Wesley.

36 SILICON VALLEY UNIVERSITY CONFIDENTIAL 36 Section 2 UNIX Editors  emacs editor Copyright @2005 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 1 2 3 4 5 6 7 8 9 10 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. 1 2 3 4 5 6 7 8 9 10

37 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. Copyright @2005 Pearson Addison-Wesley.

38 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 : Copyright @2005 Pearson Addison-Wesley.

39 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 Copyright @2005 Pearson Addison-Wesley.

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

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

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

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

44 SILICON VALLEY UNIVERSITY CONFIDENTIAL 44 Section 2 UNIX Editors  emacs editor  Creating and Editing C Programs Copyright @2005 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.

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

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

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

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


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

Similar presentations


Ads by Google