SlideShare a Scribd company logo
1 of 61
Download to read offline
Tutor Session - 2




Chulalongkorn
                                                                            Tutor Session II:


                   Introduction to UNIX
 University




                       Operating System

                Wongyos Keardsri (P’Bank)
                Department of Computer Engineering
                Faculty of Engineering, Chulalongkorn University
                Bangkok, Thailand
                Mobile Phone: 089-5993490
                E-mail: wongyos@gmail.com, MSN: bankberrer@hotmail.com
                Twitter: @wongyos
                                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                   Tutor Outline
Chulalongkorn
 University



                History of UNIX                        Directory Navigation and
                                                       Control
                Unix Structure
                                                       File Maintenance
                   UNIX Shell                          Commands
                   UNIX File System                    Display Commands
                Getting Started                   Special Unix Features
                   Logging in / Exiting
                                                  Text Processing
                   Environment Variables
                                                  Other Useful Commands
                Unix Command Line
                Structure                         vi Editor
                   System Resource
                   Commands

         2                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                        History of UNIX
Chulalongkorn
 University




                Unix (officially trademarked as UNIX®) is a
                computer operating system
                In 1965, Bell Laboratories joins with MIT and
                General Electric developed the new operating
                system named Multics
                In 1969, Some of the Bell Labs programmers
                designed and implemented the first version of the
                Unix File System on a PDP-7
                Given the name UNIX by Brian Kernighan
         3                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                         History of UNIX
Chulalongkorn
 University                                                                   (Cont)
                UNIX developer team (Bell Labs programmers)
                  Ken Thompson
                  Dennis Ritchie
                  Rudd Canaday
                  Doug McIlroy
                Languages written in UNIX
                  BCPL (Multics)
                  B (Unix)   Unix version 1.0
                  C (Unix)   After Unix version 2.0

         4                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                 Unix Structure
Chulalongkorn
 University



                Unix features
                  Multi-user and time-sharing
                  Multi-tasking
                  Multi-level (Hierarchical file system)
                  Multi-processor
                  Simple user interface
                  Simple utilities
                Free Unix-like operating systems
                  Linux
                  BSD

         5                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                               Unix Structure
Chulalongkorn
 University                                                                    (Cont)
                Several hundred utility programs
                  User commands
                  The Unix system kernel and The shells
                  System calls
                  C library functions
                  Device & network interface
                  File format
                  Games and demos
                  System maintenance

         6                               2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                   Unix Structure
Chulalongkorn
 University                                                                        (Cont)
                 Unix System Structure
                                               Kernel      - controls hardware
                                                           - handles input/output
                                                           - manages file system
                                                           - manages memory
                                                           - schedules processes
                Hardware



                              System Calls
                                                 Shell - accepts and executes user
                           Programs=Commands     commands [command interpreter]

         7                                   2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                 Unix Structure
Chulalongkorn
 University                                                                      (Cont)
                UNIX shell
                  Bourne shell (sh) -- Written by Steve Bourne, while at
                  Bell Labs. First distributed with Version 7 Unix.
                  Bourne-Again shell (bash) -- Written as part of the
                  GNU project to provide a superset of Bourne Shell
                  functionality.
                  Korn shell (ksh) -- Written by David Korn, while at
                  Bell Labs.
                  Z shell (zsh) -- considered as the most complete shell
                  C shell (csh) -- Written by Bill Joy, while at the
                  University of California, Berkeley. First distributed with
                  BSD, circa 1979.
         8                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                      Unix Structure
Chulalongkorn
 University                                                                          (Cont)
                Unix File System
                                           /               Root



                    bin      etc     lib        usr       dev       tmp         home


       sh date ls     passwd group libc.so              tty       null
                                                                            bank            u50skp
                                    bin local man


                                           bin                      hello.c cpcu
         Hierarchical file system
         9                                     2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                               Unix Structure
Chulalongkorn
 University                                                                    (Cont)
                Directory: etc, usr, home, bank, cpcu
                File: libc.so, hello.c
                Path: /home/bank/cpcu
                Two special directory entries
                  . the current directory
                  .. the parent of the current directory




         10                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                               Getting Started
Chulalongkorn
 University




                Logging in
                  After connecting with a Unix system, a user is
                  prompted for a login username, then a password.
                  Unix is case sensitive should be typed exactly as issued
                Example

                 login: root
                 password:




         11                               2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                             Getting Started
Chulalongkorn
 University                                                                   (Cont)
                Exiting
                  ^D            indicates end of data stream; can log a
                                user off.
                  ^C            interrupt
                  logout        leave the system
                  exit          leave the shell
                Terminal Type
                  vt100                Most computers
                  sun                  Sun workstation
                  xterms or xterm      X-Terminal
         12                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                             Getting Started
Chulalongkorn
 University                                                                   (Cont)
                Environment Variables
                  DISPLAY      The graphical display to use, e.g.nyssa:0.0
                  EDITOR       The path to your default editor, e.g.
                               /usr/bin/vi
                  GROUP        Your login group, e.g. staff
                  HOME         Path to your home directory, e.g.
                               /home/frank
                  HOST         The hostname of your system, e.g. nyssa
                  LOGNAME      The name you login with, e.g. frank
                  PATH         Paths to be searched for commands,
                               e.g. /usr/bin:/usr/ucb:/usr/local/bin
         13                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                           Getting Started
Chulalongkorn
 University                                                                 (Cont)
                Environment Variables (Cont)
                  PS1          The primary prompt string, Bourne
                               shell only (defaults $)
                  PS2          The secondary prompt string, Bourne
                               shell only (defaults >)
                  SHELL        The login shell you’re using, e.g.
                                /usr/bin/csh
                  TERM         Your terminal type, e.g. xterm
                  USER         Your username, e.g. frank


         14                           2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                            Getting Started
Chulalongkorn
 University                                                                  (Cont)
                Set a global environment variable
                  C shell:
                   % setenv NAME value
                  Bourne shell:
                     $ NAME=value; export NAME
                List global environmental variables with the env
                or printenv commands.
                Unset with the unsetenv (C shell) or unset
                (Bourne shell) commands.
         15                            2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                  Getting Started
Chulalongkorn
 University                                                                        (Cont)
                Set a local shell variable                   Change the shell
                   C shell:                              $   /bin/sh
                                                         $   /bin/csh
                    % set name=value                     $   /bin/ksh
                                                         $   /usr/pkg/bin/bash
                   Bourne shell:
                    $ name=value
                Display environment variables
                    echo $NAME


         16                                  2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                             Getting Started
Chulalongkorn
 University                                                                   (Cont)
                C Shell History Substitution
                  history       recall previous commands
                  !!            repeat last command
                  !n            repeat command number n
                  !-n           repeat command n from last
                  !str          repeat command that started with
                                string str
                  !?str?        repeat command with str anywhere on
                                the line
                  !?str?%       select the first argument that had str in it
         17                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                            Getting Started
Chulalongkorn
 University                                                                  (Cont)
                Control Key
                  ^S    pause display
                  ^Q    restart display
                  ^C    cancel operation
                  ^U    cancel line
                  ^D    signal end of file
                  ^V    treat following control character as
                        normal character



         18                            2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University




                Unix Command Line Structure

                $ command [options] [arguments]

                Unix manual / Help
                $ man command_name
                $ man -k keyword
                $ man -k “key words”


         19                         2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                                   (Cont)
                System Resource Commands
                  date  report the current date and time
                  cal   report the calendar
                  df    report the summary of disk blocks and inodes
                        free and in use
                  du    report amount of disk space in use
                  hostname/uname display or set (super-user only)
                        the name of the current machine
                  kill send a signal to the process with the process
                        id number (pid#) or job control number (%n).
                        The default signal is to kill the process.
         20                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                                 (Cont)
                System Resource Commands (Cont)
                  passwd      set or change your password
                  ps          show status of active processes
                  script      saves everything that appears on the
                              screen to file until exit is executed
                  stty        set or display terminal control options
                  whereis     report the binary, source, and man
                              page locations for the command
                              named
                  which       reports the path to the command or
                              the shell alias in use
         21                           2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                                (Cont)
                System Resource Commands (Cont)
                  who or w    report who is logged in and what
                              processes are running
                  whoami      report current user name
                  finger      report who is logged in
                  ifconfig    report network interfaces
                  su          switch user
                  write       send a message to another user



         22                          2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                  Unix Command Line Structure
Chulalongkorn
 University                                                                   (Cont)
                Directory Navigation and Control
                  cd [directory]
                  change directory
                  ls [options] [directory or file]
                  list directory contents or file permissions
                  mkdir [options] directory
                  make a directory
                  pwd
                  print working (current) directory
                  rmdir [options] directory
                  remove a directory

         23                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                  Unix Command Line Structure
Chulalongkorn
 University                                                                           (Cont)
                List file and directory contents
                drwxr-xr-x    3   root      wheel   512   Jul 4 23:48 2110101
                drwxr-xr-x    4   root      wheel   512   Aug 28 2005 2110313
                drwxr-xr-x    3   root      wheel   512   Aug 28 2005 Baka
                -rw-r--r--    1   root      wheel   905   Jul 9 02:09 file
                -rw-r--r--    1   root      wheel   105   Jul 9 00:05 hello.java


                Permission mode   Owner Group       Size Modified/Created           Filename
                                                         date
       Type field          Number of link



         24                                     2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                  Unix Command Line Structure
Chulalongkorn
 University                                                                       (Cont)
                Permission
                  Type field (first character)
                  Access permissions (characters 2-10):
                   • First 3 : user/owner
                   • Second 3: group
                   • Last 3: others
                  Permission mode
                   •   d   directory
                   •   r   read permission
                   •   w   write permission              drwxr-xr-x
                   •   x   execute permission
                   •   -   no permission
         25                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                               (Cont)
                Permission number
                  7           111             rwx
                  6           110             rw-
                  5           101             r-x
                  4           100             r--
                  3           011             -wx
                  2           010             -w-
                  1           001             --x
                  0           000             ---

         26                         2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                                      (Cont)
                File Maintenance Commands
                  chgrp [options] group file
                  change the group of the file
                  chmod [options] file
                  change file or directory access permissions
                  chown [options] owner file
                  change the ownership of a file; can only be done by the
                  superuser
                  cp [options] file1 file2
                  copy file1 into file2; file2 shouldn't already exist. This
                  command creates or overwrites file2.
         27                                2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                                     (Cont)
                File Maintenance Commands (Cont)
                  mv [options] file1 file2
                  move file1 into file2
                  rm [options] file
                  remove (delete) a file or directory (-r recursively
                  deletes the directory and its contents) (-i prompts
                  before removing files)




         28                               2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                 Unix Command Line Structure
Chulalongkorn
 University                                                                       (Cont)
                Display Commands
                  cat [options] file
                  concatenate (list) a file
                  echo [text string]
                  echo the text string to stdout
                  head [-number] file
                  display the first 10 (or number of) lines of a file
                  more (or less or pg ) [options] file
                  page through a text file
                  tail [options] file
                  display the last few lines (or parts) of a file

         29                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                 Special Unix Features
Chulalongkorn
 University




                I/O redirection and piping
                  Output redirection to a file
                  Input redirection from a file
                  Piping
                  Output of one command becomes the input of a
                  subsequent command
                There are 3 standard file descriptors:
                  stdin    0 Standard input to the program
                  stdout   1 Standard output from the program
                  stderr   2 Standard error output from the program
         30                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                   Special Unix Features
Chulalongkorn
 University                                                                   (Cont)
                File Redirection
                  >       redirect standard output to file
                          command > outputfile
                  >>      append standard output to file
                          command >> outputfile
                  <       input redirection from file
                          command < inputfile
                  |       pipe output to another command
                          command1 | command2

         31                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                  Special Unix Features
Chulalongkorn
 University                                                                    (Cont)
                File Redirection (csh)
                  >& file        redirect stdout and stderr to file
                  >>&            file append stdout and stderr to file
                  |&             command pipe stdout and stderr to
                                 command
                To redirect stdout and stderr to separate files:
                  % (command > outfile) >& errfile




         32                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                         Special Unix Features
Chulalongkorn
 University                                                                              (Cont)
                File Redirection (sh)
                   2> file              redirect stderr to file
                   > file 2>&1          direct both stdout and stderr to file
                   >> file 2>&1         append both stdout and stderr to file
                   2>&1|command         pipe stdout and stderr to command
                To redirect stdout and stderr to two separate files:
                   $command > outfile 2> errfile
                To discard stderr:
                   $ command 2> /dev/null
                   (/dev/null is a black hole for bits)


         33                                        2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                 Special Unix Features
Chulalongkorn
 University                                                                   (Cont)
                Wild Cards
                  ?     match any single character
                  *     match any string of zero or more characters
                  [abc] match anyone of the enclosed characters
                  [a-s] match any character in the range a through s
                  [!def] (sh) match any characters not one of
                  [^def] (csh) the enclosed characters




         34                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                  Special Unix Features
Chulalongkorn
 University                                                                    (Cont)
                Control Over Command Execution
                  Background (non-interactive)
                   command &
                  Sequential
                   command1 ; command2
                  Subprocess (run as an atomic unit)
                   (command)




         35                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                  Special Unix Features
Chulalongkorn
 University                                                                     (Cont)
                Control Over Command Execution (Cont)
                  Conditional (program exit status determines success
                  or failure)
                   • OR command1 || command2
                      – (run command2 if command1 fails)
                   • AND command1 && command2
                      – (run command2 if command1 succeeds)




         36                               2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                              Text Processing
Chulalongkorn
 University



                Filter
                   A filter (in Unix) is a program that reads some input,
                   performs a simple translation on it, and writes some
                   output
                Examples of Unix filters
                   grep
                   sort
                   wc
                   awk
                   vi
                   sed
         37                                2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                              Text Processing
Chulalongkorn
 University                                                                      (Cont)
                Text Processing Commands
                  awk [options] file
                  scan for patterns in a file and process the results
                  grep [options] 'search string' file
                  search the argument (in this case probably a file) for all
                  occurrences of the search string, and list them.
                  sed [options] file
                  stream editor for editing files from a script or from the
                  command line


         38                                2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                 Text Processing
Chulalongkorn
 University                                                                         (Cont)
                Regular expressions
                  Regular expressions come in three different forms
                   • Anchor tie the pattern to a location on the line
                   • Character sets match a single character at a single position
                   • Modifiers specify how many times to repeat the previous
                     expression
                  Regular expressions can be combined to form longer
                  regular expressions




         39                                   2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                           Text Processing
Chulalongkorn
 University                                                                   (Cont)
                Regular expressions (Cont)
                  .     match any single character except newline
                  *     match zero or more instances of single
                        expression preceding it
                  [abc] match any of the characters enclosed
                  [a-d] match any character in enclosed range
                  [^abc]match any character NOT in the enclosed set
                  ^exp regular expression must start at the beginning
                        of the line


         40                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                           Text Processing
Chulalongkorn
 University                                                                   (Cont)
                Regular expressions (Cont)
                  exp$   regular expression must end at the beginning
                         of the line
                        treat the next character literally




         41                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                            Other Useful Commands
Chulalongkorn
 University




                Working With Files
                  cmp [options] file1 file2
                  compare two files and list where differences occur
                  (text or binary files)
                  cut [options] [file(s)]
                  cut specified field(s)/character(s) from lines in file(s)
                  diff [options] file1 file2
                  compare the two files and display the differences (text
                  files only)
                  file [options] file
                  classify the file type
         42                                2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                           Other Useful Commands
Chulalongkorn
 University                                                                     (Cont)
                Working With Files (Cont)
                  find directory [options] [actions]
                  find files matching a type or pattern
                  ln [options] source_file
                  target link the source_file to the target
                  paste [options] file
                  paste field(s) onto the lines in file
                  sort [options] file
                  sort the lines of the file according to the options
                  chosen

         43                               2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                           Other Useful Commands
Chulalongkorn
 University                                                                    (Cont)
                Working With Files (Cont)
                  strings [options] file
                  report any sequence of 4 or more printable characters
                  ending in <NL> or <NULL>. Usually used to search
                  binary files for ASCII strings.
                  tee [options] file
                  copy stdout to one or more files
                  touch [options] [date] file
                  create an empty file, or update the access time of an
                  existing file

         44                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                            Other Useful Commands
Chulalongkorn
 University                                                                      (Cont)
                Working With Files (Cont)
                  tr [options] string1 string2
                  translate the characters in string1 from stdin into
                  those in string2 in stdout
                  uniq [options] file
                  remove repeated lines in a file
                  wc [options] [file(s)]
                  display word (or character or line) count for file(s)



         45                                2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                           Other Useful Commands
Chulalongkorn
 University                                                                    (Cont)
                File Archiving, Compression and Conversion
                  compress/uncompress/zcat [options]
                  file[.Z]
                  compress or uncompress a file. Compressed files are
                  stored with a .Z ending.
                  gzip/gunzip/zcat [options] file[.gz]
                  compress or uncompress a file. Compressed files are
                  stored with a .gz ending




         46                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                            Other Useful Commands
Chulalongkorn
 University                                                                       (Cont)
                File Archiving, Compression and Conversion
                  tar key[options] [file(s)]
                  tape archiver--refer to man pages for details on
                  creating, listing, and retrieving from archive files. Tar
                  files can be stored on tape or disk.




         47                                 2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                           Other Useful Commands
Chulalongkorn
 University                                                                    (Cont)
                Remote Connections
                  finger [options] user[@hostname]
                  report information about users on local and remote
                  machines
                  ftp [options] host
                  transfer file(s) using file transfer protocol
                  rcp [options] hostname
                  remotely copy files from this machine to another
                  machine


         48                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                           Other Useful Commands
Chulalongkorn
 University                                                                    (Cont)
                Remote Connections
                  rlogin [options] hostname
                  login remotely to another machine
                  rsh [options] hostname
                  remote shell to run on another machine
                  telnet [host [port]]
                  communicate with another host using telnet protocol




         49                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                               Vi Editor
Chulalongkorn
 University




                UNIX Editors
                  vi
                  emacs
                  pico
                Vi is a modal editor (2 modes)
                  Insert mode <i> key
                   • Text insertion
                  Command mode <escape> key
                   • All commands


         50                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                               Vi Editor
Chulalongkorn
 University                                      vi Quick Reference Guide

                Cursor Movement Commands
                  (n)    indicates a number, and is optional
                  (n)h   left (n) space(s)
                  (n)j   down (n) space(s)
                  (n)k   up (n) space(s)
                  (n)l   right (n) space(s)
                  ^F     forward one screen
                  ^B     back one screen
                  ^D     down half screen
                  ^U     up half screen
         51                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                               Vi Editor
Chulalongkorn
 University                            vi Quick Reference Guide (Cont)

                Cursor Movement Commands (Cont)
                  H      beginning of top line of screen
                  M      beginning of middle line of screen
                  L      beginning of last line of screen
                  G      beginning of last line of file
                  (n)G   move to beginning of line (n)
                  0      (zero) beginning of line
                  $      end of line
                  (n)w   forward (n) word(s)

         52                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                                Vi Editor
Chulalongkorn
 University                             vi Quick Reference Guide (Cont)

                Cursor Movement Commands (Cont)
                  (n)b    back (n) word(s)
                  e       end of word
                Inserting Text
                  i       insert text before the cursor
                  a       append text after the cursor (does not
                          overwrite other text)
                  I       insert text at the beginning of the line
                  A       append text to the end of the line
                  r       replace the character under the cursor with
                          the next character typed
         53                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                                Vi Editor
Chulalongkorn
 University                             vi Quick Reference Guide (Cont)

                Inserting Text (Cont)
                  R       Overwrite characters until the end of the line
                          (or until escape is pressed to change
                          command)
                  o       (alpha o) open new line after the current line
                          to type text
                  O       (alpha O) open new line before the current
                          line to type text



         54                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                                Vi Editor
Chulalongkorn
 University                             vi Quick Reference Guide (Cont)

                Deleting Text
                  dd      deletes current line
                  (n)dd   deletes (n) line(s)
                  (n)dw   deletes (n) word(s)
                  D       deletes from cursor to end of line
                  x       deletes current character
                  (n)x    deletes (n) character(s)
                  X       deletes previous character



         55                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                                Vi Editor
Chulalongkorn
 University                             vi Quick Reference Guide (Cont)

                Change Commands
                  (n)cc changes (n) characters on line(s) until end of
                        the line (or until escape is pressed)
                  cw    changes characters of word until end of the
                        word (or until escape is pressed)
                  (n)cw changes characters of the next (n) words
                  c$    changes text to the end of the line
                  ct(x) changes text to the letter (x)



         56                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                              Vi Editor
Chulalongkorn
 University                           vi Quick Reference Guide (Cont)

                Change Commands (Cont)
                  C     changes remaining text on the current line
                        (until stopped by escape key)
                  ~     changes the case of the current character
                  J     joins the current line and the next line
                  u     undo the last command just done on this line
                  .     repeats last change
                  s     substitutes text for current character
                  S     substitutes text for current line

         57                            2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                                Vi Editor
Chulalongkorn
 University                             vi Quick Reference Guide (Cont)

                Change Commands (Cont)
                  :s      substitutes new word(s) for old
                  :<      line nos effected> s/old/new/g
                  &       repeats last substitution (:s) command.
                  (n)yy   yanks (n) lines to buffer
                  y(n)w   yanks (n) words to buffer
                  p       puts yanked or deleted text after cursor
                  P       puts yanked or deleted text before cursor



         58                              2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                               Vi Editor
Chulalongkorn
 University                            vi Quick Reference Guide (Cont)

                File Manipulation
                  :w(file)      writes changes to file (default is
                                current file)
                  :wq           writes changes to current file and quits
                                edit session
                  :w!(file)     overwrites file (default is current file)
                  :q            quits edit session w/no changes made
                  :q!           quits edit session and discards changes
                  :n            edits next file in argument list


         59                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                               Vi Editor
Chulalongkorn
 University                            vi Quick Reference Guide (Cont)

                File Manipulation (Cont)
                  :f(name)   changes name of current file to (name)
                  :r(file)   reads contents of file into current edit
                             at the current cursor position (insert a
                             file)
                  :!(command) shell escape
                  :r!(command) inserts result of shell command at
                             cursor position
                  ZZ         write changes to current file and exit


         60                             2110313 Operating Systems and System Programs (1/2010)
Tutor Session - 2



                                                               End
Chulalongkorn
 University




                Question ?


                           … Answer
         61              2110313 Operating Systems and System Programs (1/2010)

More Related Content

What's hot

Processes in unix
Processes in unixProcesses in unix
Processes in unix
miau_max
 
User level view of os
User level view of osUser level view of os
User level view of os
Mohd Arif
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training
Nancy Thomas
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 

What's hot (20)

Processes in unix
Processes in unixProcesses in unix
Processes in unix
 
Introduction to System Calls
Introduction to System CallsIntroduction to System Calls
Introduction to System Calls
 
Studies
StudiesStudies
Studies
 
Linux internals v4
Linux internals v4Linux internals v4
Linux internals v4
 
User level view of os
User level view of osUser level view of os
User level view of os
 
UNIX Operating System ppt
UNIX Operating System pptUNIX Operating System ppt
UNIX Operating System ppt
 
Unix kernal
Unix kernalUnix kernal
Unix kernal
 
Unix lecture1
Unix lecture1Unix lecture1
Unix lecture1
 
unix training | unix training videos | unix course unix online training
unix training |  unix training videos |  unix course  unix online training unix training |  unix training videos |  unix course  unix online training
unix training | unix training videos | unix course unix online training
 
Lecture01 introduction
Lecture01 introductionLecture01 introduction
Lecture01 introduction
 
Unix Introduction
Unix IntroductionUnix Introduction
Unix Introduction
 
Unit 1-a-brief-history-of-unix-ppt
Unit 1-a-brief-history-of-unix-pptUnit 1-a-brief-history-of-unix-ppt
Unit 1-a-brief-history-of-unix-ppt
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Unix seminar
Unix seminarUnix seminar
Unix seminar
 
Intro tounix
Intro tounixIntro tounix
Intro tounix
 
Unix operating system architecture with file structure
Unix operating system architecture with file structure Unix operating system architecture with file structure
Unix operating system architecture with file structure
 
Kernal
KernalKernal
Kernal
 
Unix
UnixUnix
Unix
 

Viewers also liked

SysProg-Tutor 01 Introduction to C Programming Language
SysProg-Tutor 01 Introduction to C Programming LanguageSysProg-Tutor 01 Introduction to C Programming Language
SysProg-Tutor 01 Introduction to C Programming Language
Wongyos Keardsri
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
Eric Wilson
 
Java-Answer Chapter 12-13 (For Print)
Java-Answer Chapter 12-13 (For Print)Java-Answer Chapter 12-13 (For Print)
Java-Answer Chapter 12-13 (For Print)
Wongyos Keardsri
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
Dr.Ravi
 
shell programming training | shell programming classes | unix shell programmi...
shell programming training | shell programming classes | unix shell programmi...shell programming training | shell programming classes | unix shell programmi...
shell programming training | shell programming classes | unix shell programmi...
Nancy Thomas
 
17. Computer System Configuration And Methods
17. Computer System   Configuration And Methods17. Computer System   Configuration And Methods
17. Computer System Configuration And Methods
New Era University
 

Viewers also liked (20)

Unix operating system
Unix operating systemUnix operating system
Unix operating system
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 
SysProg-Tutor 01 Introduction to C Programming Language
SysProg-Tutor 01 Introduction to C Programming LanguageSysProg-Tutor 01 Introduction to C Programming Language
SysProg-Tutor 01 Introduction to C Programming Language
 
How to Study and Research in Computer-related Master Program
How to Study and Research in Computer-related Master ProgramHow to Study and Research in Computer-related Master Program
How to Study and Research in Computer-related Master Program
 
IP address anonymization
IP address anonymizationIP address anonymization
IP address anonymization
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Unix - An Introduction
Unix - An IntroductionUnix - An Introduction
Unix - An Introduction
 
Unix
UnixUnix
Unix
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Java-Answer Chapter 12-13 (For Print)
Java-Answer Chapter 12-13 (For Print)Java-Answer Chapter 12-13 (For Print)
Java-Answer Chapter 12-13 (For Print)
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpoint
 
shell programming training | shell programming classes | unix shell programmi...
shell programming training | shell programming classes | unix shell programmi...shell programming training | shell programming classes | unix shell programmi...
shell programming training | shell programming classes | unix shell programmi...
 
Java-Chapter 12 Classes and Objects
Java-Chapter 12 Classes and ObjectsJava-Chapter 12 Classes and Objects
Java-Chapter 12 Classes and Objects
 
Java-Chapter 13 Advanced Classes and Objects
Java-Chapter 13 Advanced Classes and ObjectsJava-Chapter 13 Advanced Classes and Objects
Java-Chapter 13 Advanced Classes and Objects
 
Kernel I/O Subsystem
Kernel I/O SubsystemKernel I/O Subsystem
Kernel I/O Subsystem
 
The next generation intelligent transport systems: standards and applications
The next generation intelligent transport systems: standards and applicationsThe next generation intelligent transport systems: standards and applications
The next generation intelligent transport systems: standards and applications
 
17. Computer System Configuration And Methods
17. Computer System   Configuration And Methods17. Computer System   Configuration And Methods
17. Computer System Configuration And Methods
 
Chapter 13 - I/O Systems
Chapter 13 - I/O SystemsChapter 13 - I/O Systems
Chapter 13 - I/O Systems
 

Similar to SysProg-Tutor 02 Introduction to Unix Operating System

Unix introduction
Unix  introductionUnix  introduction
Unix introduction
Kona Yuki
 
User and Operating-System Interface We mentioned earlier that there ar.docx
User and Operating-System Interface We mentioned earlier that there ar.docxUser and Operating-System Interface We mentioned earlier that there ar.docx
User and Operating-System Interface We mentioned earlier that there ar.docx
StewartyUMGlovern
 

Similar to SysProg-Tutor 02 Introduction to Unix Operating System (20)

Unix introduction
Unix  introductionUnix  introduction
Unix introduction
 
Presentation1.pdf
Presentation1.pdfPresentation1.pdf
Presentation1.pdf
 
UNIX_module1.pptx
UNIX_module1.pptxUNIX_module1.pptx
UNIX_module1.pptx
 
Mca ii os u-5 unix linux file system
Mca  ii  os u-5 unix linux file systemMca  ii  os u-5 unix linux file system
Mca ii os u-5 unix linux file system
 
CHAPTER 1 INTRODUCTION TO UNIX.pptx
CHAPTER 1 INTRODUCTION TO UNIX.pptxCHAPTER 1 INTRODUCTION TO UNIX.pptx
CHAPTER 1 INTRODUCTION TO UNIX.pptx
 
Hybrid kernel
Hybrid kernelHybrid kernel
Hybrid kernel
 
UNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-IUNIX INTERNALS UNIT-I
UNIX INTERNALS UNIT-I
 
L1 Introduction to OS.pptx
L1 Introduction to OS.pptxL1 Introduction to OS.pptx
L1 Introduction to OS.pptx
 
Unix Training - 1
Unix Training - 1Unix Training - 1
Unix Training - 1
 
SEC.3 Linux vs Unix Kernel.pptxnnnnnnnnnnnnnnnnnnnn
SEC.3 Linux vs Unix Kernel.pptxnnnnnnnnnnnnnnnnnnnnSEC.3 Linux vs Unix Kernel.pptxnnnnnnnnnnnnnnnnnnnn
SEC.3 Linux vs Unix Kernel.pptxnnnnnnnnnnnnnnnnnnnn
 
Structure of Unix Operating System.pptx
Structure of Unix Operating System.pptxStructure of Unix Operating System.pptx
Structure of Unix Operating System.pptx
 
CS403: Operating System : Lec 6 OS Structure.pptx
CS403: Operating System : Lec 6 OS Structure.pptxCS403: Operating System : Lec 6 OS Structure.pptx
CS403: Operating System : Lec 6 OS Structure.pptx
 
Introduction to unix
Introduction to unixIntroduction to unix
Introduction to unix
 
Ch1-Unix.pptx
Ch1-Unix.pptxCh1-Unix.pptx
Ch1-Unix.pptx
 
User and Operating-System Interface We mentioned earlier that there ar.docx
User and Operating-System Interface We mentioned earlier that there ar.docxUser and Operating-System Interface We mentioned earlier that there ar.docx
User and Operating-System Interface We mentioned earlier that there ar.docx
 
KERNEL.pptx
KERNEL.pptxKERNEL.pptx
KERNEL.pptx
 
Architecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docxArchitecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docx
 
purnima.docx
purnima.docxpurnima.docx
purnima.docx
 
niyonika.docx
niyonika.docxniyonika.docx
niyonika.docx
 
khushi.docx
khushi.docxkhushi.docx
khushi.docx
 

More from Wongyos Keardsri

Discrete-Chapter 11 Graphs Part III
Discrete-Chapter 11 Graphs Part IIIDiscrete-Chapter 11 Graphs Part III
Discrete-Chapter 11 Graphs Part III
Wongyos Keardsri
 
Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part II
Wongyos Keardsri
 
Discrete-Chapter 11 Graphs Part I
Discrete-Chapter 11 Graphs Part IDiscrete-Chapter 11 Graphs Part I
Discrete-Chapter 11 Graphs Part I
Wongyos Keardsri
 
Discrete-Chapter 09 Algorithms
Discrete-Chapter 09 AlgorithmsDiscrete-Chapter 09 Algorithms
Discrete-Chapter 09 Algorithms
Wongyos Keardsri
 
Discrete-Chapter 08 Relations
Discrete-Chapter 08 RelationsDiscrete-Chapter 08 Relations
Discrete-Chapter 08 Relations
Wongyos Keardsri
 
Discrete-Chapter 07 Probability
Discrete-Chapter 07 ProbabilityDiscrete-Chapter 07 Probability
Discrete-Chapter 07 Probability
Wongyos Keardsri
 
Discrete-Chapter 06 Counting
Discrete-Chapter 06 CountingDiscrete-Chapter 06 Counting
Discrete-Chapter 06 Counting
Wongyos Keardsri
 
Discrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and ProofsDiscrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and Proofs
Wongyos Keardsri
 
Discrete-Chapter 04 Logic Part II
Discrete-Chapter 04 Logic Part IIDiscrete-Chapter 04 Logic Part II
Discrete-Chapter 04 Logic Part II
Wongyos Keardsri
 
Discrete-Chapter 04 Logic Part I
Discrete-Chapter 04 Logic Part IDiscrete-Chapter 04 Logic Part I
Discrete-Chapter 04 Logic Part I
Wongyos Keardsri
 
Discrete-Chapter 03 Matrices
Discrete-Chapter 03 MatricesDiscrete-Chapter 03 Matrices
Discrete-Chapter 03 Matrices
Wongyos Keardsri
 
Discrete-Chapter 02 Functions and Sequences
Discrete-Chapter 02 Functions and SequencesDiscrete-Chapter 02 Functions and Sequences
Discrete-Chapter 02 Functions and Sequences
Wongyos Keardsri
 
Discrete-Chapter 12 Modeling Computation
Discrete-Chapter 12 Modeling ComputationDiscrete-Chapter 12 Modeling Computation
Discrete-Chapter 12 Modeling Computation
Wongyos Keardsri
 

More from Wongyos Keardsri (20)

Discrete-Chapter 11 Graphs Part III
Discrete-Chapter 11 Graphs Part IIIDiscrete-Chapter 11 Graphs Part III
Discrete-Chapter 11 Graphs Part III
 
Discrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part IIDiscrete-Chapter 11 Graphs Part II
Discrete-Chapter 11 Graphs Part II
 
Discrete-Chapter 11 Graphs Part I
Discrete-Chapter 11 Graphs Part IDiscrete-Chapter 11 Graphs Part I
Discrete-Chapter 11 Graphs Part I
 
Discrete-Chapter 10 Trees
Discrete-Chapter 10 TreesDiscrete-Chapter 10 Trees
Discrete-Chapter 10 Trees
 
Discrete-Chapter 09 Algorithms
Discrete-Chapter 09 AlgorithmsDiscrete-Chapter 09 Algorithms
Discrete-Chapter 09 Algorithms
 
Discrete-Chapter 08 Relations
Discrete-Chapter 08 RelationsDiscrete-Chapter 08 Relations
Discrete-Chapter 08 Relations
 
Discrete-Chapter 07 Probability
Discrete-Chapter 07 ProbabilityDiscrete-Chapter 07 Probability
Discrete-Chapter 07 Probability
 
Discrete-Chapter 06 Counting
Discrete-Chapter 06 CountingDiscrete-Chapter 06 Counting
Discrete-Chapter 06 Counting
 
Discrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and ProofsDiscrete-Chapter 05 Inference and Proofs
Discrete-Chapter 05 Inference and Proofs
 
Discrete-Chapter 04 Logic Part II
Discrete-Chapter 04 Logic Part IIDiscrete-Chapter 04 Logic Part II
Discrete-Chapter 04 Logic Part II
 
Discrete-Chapter 04 Logic Part I
Discrete-Chapter 04 Logic Part IDiscrete-Chapter 04 Logic Part I
Discrete-Chapter 04 Logic Part I
 
Discrete-Chapter 03 Matrices
Discrete-Chapter 03 MatricesDiscrete-Chapter 03 Matrices
Discrete-Chapter 03 Matrices
 
Discrete-Chapter 02 Functions and Sequences
Discrete-Chapter 02 Functions and SequencesDiscrete-Chapter 02 Functions and Sequences
Discrete-Chapter 02 Functions and Sequences
 
Discrete-Chapter 01 Sets
Discrete-Chapter 01 SetsDiscrete-Chapter 01 Sets
Discrete-Chapter 01 Sets
 
Discrete-Chapter 12 Modeling Computation
Discrete-Chapter 12 Modeling ComputationDiscrete-Chapter 12 Modeling Computation
Discrete-Chapter 12 Modeling Computation
 
Java-Chapter 14 Creating Graphics with DWindow
Java-Chapter 14 Creating Graphics with DWindowJava-Chapter 14 Creating Graphics with DWindow
Java-Chapter 14 Creating Graphics with DWindow
 
Java-Chapter 11 Recursions
Java-Chapter 11 RecursionsJava-Chapter 11 Recursions
Java-Chapter 11 Recursions
 
Java-Chapter 10 Two Dimensional Arrays
Java-Chapter 10 Two Dimensional ArraysJava-Chapter 10 Two Dimensional Arrays
Java-Chapter 10 Two Dimensional Arrays
 
Java-Chapter 09 Advanced Statements and Applications
Java-Chapter 09 Advanced Statements and ApplicationsJava-Chapter 09 Advanced Statements and Applications
Java-Chapter 09 Advanced Statements and Applications
 
Java-Chapter 08 Methods
Java-Chapter 08 MethodsJava-Chapter 08 Methods
Java-Chapter 08 Methods
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

SysProg-Tutor 02 Introduction to Unix Operating System

  • 1. Tutor Session - 2 Chulalongkorn Tutor Session II: Introduction to UNIX University Operating System Wongyos Keardsri (P’Bank) Department of Computer Engineering Faculty of Engineering, Chulalongkorn University Bangkok, Thailand Mobile Phone: 089-5993490 E-mail: wongyos@gmail.com, MSN: bankberrer@hotmail.com Twitter: @wongyos 2110313 Operating Systems and System Programs (1/2010)
  • 2. Tutor Session - 2 Tutor Outline Chulalongkorn University History of UNIX Directory Navigation and Control Unix Structure File Maintenance UNIX Shell Commands UNIX File System Display Commands Getting Started Special Unix Features Logging in / Exiting Text Processing Environment Variables Other Useful Commands Unix Command Line Structure vi Editor System Resource Commands 2 2110313 Operating Systems and System Programs (1/2010)
  • 3. Tutor Session - 2 History of UNIX Chulalongkorn University Unix (officially trademarked as UNIX®) is a computer operating system In 1965, Bell Laboratories joins with MIT and General Electric developed the new operating system named Multics In 1969, Some of the Bell Labs programmers designed and implemented the first version of the Unix File System on a PDP-7 Given the name UNIX by Brian Kernighan 3 2110313 Operating Systems and System Programs (1/2010)
  • 4. Tutor Session - 2 History of UNIX Chulalongkorn University (Cont) UNIX developer team (Bell Labs programmers) Ken Thompson Dennis Ritchie Rudd Canaday Doug McIlroy Languages written in UNIX BCPL (Multics) B (Unix) Unix version 1.0 C (Unix) After Unix version 2.0 4 2110313 Operating Systems and System Programs (1/2010)
  • 5. Tutor Session - 2 Unix Structure Chulalongkorn University Unix features Multi-user and time-sharing Multi-tasking Multi-level (Hierarchical file system) Multi-processor Simple user interface Simple utilities Free Unix-like operating systems Linux BSD 5 2110313 Operating Systems and System Programs (1/2010)
  • 6. Tutor Session - 2 Unix Structure Chulalongkorn University (Cont) Several hundred utility programs User commands The Unix system kernel and The shells System calls C library functions Device & network interface File format Games and demos System maintenance 6 2110313 Operating Systems and System Programs (1/2010)
  • 7. Tutor Session - 2 Unix Structure Chulalongkorn University (Cont) Unix System Structure Kernel - controls hardware - handles input/output - manages file system - manages memory - schedules processes Hardware System Calls Shell - accepts and executes user Programs=Commands commands [command interpreter] 7 2110313 Operating Systems and System Programs (1/2010)
  • 8. Tutor Session - 2 Unix Structure Chulalongkorn University (Cont) UNIX shell Bourne shell (sh) -- Written by Steve Bourne, while at Bell Labs. First distributed with Version 7 Unix. Bourne-Again shell (bash) -- Written as part of the GNU project to provide a superset of Bourne Shell functionality. Korn shell (ksh) -- Written by David Korn, while at Bell Labs. Z shell (zsh) -- considered as the most complete shell C shell (csh) -- Written by Bill Joy, while at the University of California, Berkeley. First distributed with BSD, circa 1979. 8 2110313 Operating Systems and System Programs (1/2010)
  • 9. Tutor Session - 2 Unix Structure Chulalongkorn University (Cont) Unix File System / Root bin etc lib usr dev tmp home sh date ls passwd group libc.so tty null bank u50skp bin local man bin hello.c cpcu Hierarchical file system 9 2110313 Operating Systems and System Programs (1/2010)
  • 10. Tutor Session - 2 Unix Structure Chulalongkorn University (Cont) Directory: etc, usr, home, bank, cpcu File: libc.so, hello.c Path: /home/bank/cpcu Two special directory entries . the current directory .. the parent of the current directory 10 2110313 Operating Systems and System Programs (1/2010)
  • 11. Tutor Session - 2 Getting Started Chulalongkorn University Logging in After connecting with a Unix system, a user is prompted for a login username, then a password. Unix is case sensitive should be typed exactly as issued Example login: root password: 11 2110313 Operating Systems and System Programs (1/2010)
  • 12. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) Exiting ^D indicates end of data stream; can log a user off. ^C interrupt logout leave the system exit leave the shell Terminal Type vt100 Most computers sun Sun workstation xterms or xterm X-Terminal 12 2110313 Operating Systems and System Programs (1/2010)
  • 13. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) Environment Variables DISPLAY The graphical display to use, e.g.nyssa:0.0 EDITOR The path to your default editor, e.g. /usr/bin/vi GROUP Your login group, e.g. staff HOME Path to your home directory, e.g. /home/frank HOST The hostname of your system, e.g. nyssa LOGNAME The name you login with, e.g. frank PATH Paths to be searched for commands, e.g. /usr/bin:/usr/ucb:/usr/local/bin 13 2110313 Operating Systems and System Programs (1/2010)
  • 14. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) Environment Variables (Cont) PS1 The primary prompt string, Bourne shell only (defaults $) PS2 The secondary prompt string, Bourne shell only (defaults >) SHELL The login shell you’re using, e.g. /usr/bin/csh TERM Your terminal type, e.g. xterm USER Your username, e.g. frank 14 2110313 Operating Systems and System Programs (1/2010)
  • 15. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) Set a global environment variable C shell: % setenv NAME value Bourne shell: $ NAME=value; export NAME List global environmental variables with the env or printenv commands. Unset with the unsetenv (C shell) or unset (Bourne shell) commands. 15 2110313 Operating Systems and System Programs (1/2010)
  • 16. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) Set a local shell variable Change the shell C shell: $ /bin/sh $ /bin/csh % set name=value $ /bin/ksh $ /usr/pkg/bin/bash Bourne shell: $ name=value Display environment variables echo $NAME 16 2110313 Operating Systems and System Programs (1/2010)
  • 17. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) C Shell History Substitution history recall previous commands !! repeat last command !n repeat command number n !-n repeat command n from last !str repeat command that started with string str !?str? repeat command with str anywhere on the line !?str?% select the first argument that had str in it 17 2110313 Operating Systems and System Programs (1/2010)
  • 18. Tutor Session - 2 Getting Started Chulalongkorn University (Cont) Control Key ^S pause display ^Q restart display ^C cancel operation ^U cancel line ^D signal end of file ^V treat following control character as normal character 18 2110313 Operating Systems and System Programs (1/2010)
  • 19. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University Unix Command Line Structure $ command [options] [arguments] Unix manual / Help $ man command_name $ man -k keyword $ man -k “key words” 19 2110313 Operating Systems and System Programs (1/2010)
  • 20. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) System Resource Commands date report the current date and time cal report the calendar df report the summary of disk blocks and inodes free and in use du report amount of disk space in use hostname/uname display or set (super-user only) the name of the current machine kill send a signal to the process with the process id number (pid#) or job control number (%n). The default signal is to kill the process. 20 2110313 Operating Systems and System Programs (1/2010)
  • 21. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) System Resource Commands (Cont) passwd set or change your password ps show status of active processes script saves everything that appears on the screen to file until exit is executed stty set or display terminal control options whereis report the binary, source, and man page locations for the command named which reports the path to the command or the shell alias in use 21 2110313 Operating Systems and System Programs (1/2010)
  • 22. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) System Resource Commands (Cont) who or w report who is logged in and what processes are running whoami report current user name finger report who is logged in ifconfig report network interfaces su switch user write send a message to another user 22 2110313 Operating Systems and System Programs (1/2010)
  • 23. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) Directory Navigation and Control cd [directory] change directory ls [options] [directory or file] list directory contents or file permissions mkdir [options] directory make a directory pwd print working (current) directory rmdir [options] directory remove a directory 23 2110313 Operating Systems and System Programs (1/2010)
  • 24. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) List file and directory contents drwxr-xr-x 3 root wheel 512 Jul 4 23:48 2110101 drwxr-xr-x 4 root wheel 512 Aug 28 2005 2110313 drwxr-xr-x 3 root wheel 512 Aug 28 2005 Baka -rw-r--r-- 1 root wheel 905 Jul 9 02:09 file -rw-r--r-- 1 root wheel 105 Jul 9 00:05 hello.java Permission mode Owner Group Size Modified/Created Filename date Type field Number of link 24 2110313 Operating Systems and System Programs (1/2010)
  • 25. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) Permission Type field (first character) Access permissions (characters 2-10): • First 3 : user/owner • Second 3: group • Last 3: others Permission mode • d directory • r read permission • w write permission drwxr-xr-x • x execute permission • - no permission 25 2110313 Operating Systems and System Programs (1/2010)
  • 26. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) Permission number 7 111 rwx 6 110 rw- 5 101 r-x 4 100 r-- 3 011 -wx 2 010 -w- 1 001 --x 0 000 --- 26 2110313 Operating Systems and System Programs (1/2010)
  • 27. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) File Maintenance Commands chgrp [options] group file change the group of the file chmod [options] file change file or directory access permissions chown [options] owner file change the ownership of a file; can only be done by the superuser cp [options] file1 file2 copy file1 into file2; file2 shouldn't already exist. This command creates or overwrites file2. 27 2110313 Operating Systems and System Programs (1/2010)
  • 28. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) File Maintenance Commands (Cont) mv [options] file1 file2 move file1 into file2 rm [options] file remove (delete) a file or directory (-r recursively deletes the directory and its contents) (-i prompts before removing files) 28 2110313 Operating Systems and System Programs (1/2010)
  • 29. Tutor Session - 2 Unix Command Line Structure Chulalongkorn University (Cont) Display Commands cat [options] file concatenate (list) a file echo [text string] echo the text string to stdout head [-number] file display the first 10 (or number of) lines of a file more (or less or pg ) [options] file page through a text file tail [options] file display the last few lines (or parts) of a file 29 2110313 Operating Systems and System Programs (1/2010)
  • 30. Tutor Session - 2 Special Unix Features Chulalongkorn University I/O redirection and piping Output redirection to a file Input redirection from a file Piping Output of one command becomes the input of a subsequent command There are 3 standard file descriptors: stdin 0 Standard input to the program stdout 1 Standard output from the program stderr 2 Standard error output from the program 30 2110313 Operating Systems and System Programs (1/2010)
  • 31. Tutor Session - 2 Special Unix Features Chulalongkorn University (Cont) File Redirection > redirect standard output to file command > outputfile >> append standard output to file command >> outputfile < input redirection from file command < inputfile | pipe output to another command command1 | command2 31 2110313 Operating Systems and System Programs (1/2010)
  • 32. Tutor Session - 2 Special Unix Features Chulalongkorn University (Cont) File Redirection (csh) >& file redirect stdout and stderr to file >>& file append stdout and stderr to file |& command pipe stdout and stderr to command To redirect stdout and stderr to separate files: % (command > outfile) >& errfile 32 2110313 Operating Systems and System Programs (1/2010)
  • 33. Tutor Session - 2 Special Unix Features Chulalongkorn University (Cont) File Redirection (sh) 2> file redirect stderr to file > file 2>&1 direct both stdout and stderr to file >> file 2>&1 append both stdout and stderr to file 2>&1|command pipe stdout and stderr to command To redirect stdout and stderr to two separate files: $command > outfile 2> errfile To discard stderr: $ command 2> /dev/null (/dev/null is a black hole for bits) 33 2110313 Operating Systems and System Programs (1/2010)
  • 34. Tutor Session - 2 Special Unix Features Chulalongkorn University (Cont) Wild Cards ? match any single character * match any string of zero or more characters [abc] match anyone of the enclosed characters [a-s] match any character in the range a through s [!def] (sh) match any characters not one of [^def] (csh) the enclosed characters 34 2110313 Operating Systems and System Programs (1/2010)
  • 35. Tutor Session - 2 Special Unix Features Chulalongkorn University (Cont) Control Over Command Execution Background (non-interactive) command & Sequential command1 ; command2 Subprocess (run as an atomic unit) (command) 35 2110313 Operating Systems and System Programs (1/2010)
  • 36. Tutor Session - 2 Special Unix Features Chulalongkorn University (Cont) Control Over Command Execution (Cont) Conditional (program exit status determines success or failure) • OR command1 || command2 – (run command2 if command1 fails) • AND command1 && command2 – (run command2 if command1 succeeds) 36 2110313 Operating Systems and System Programs (1/2010)
  • 37. Tutor Session - 2 Text Processing Chulalongkorn University Filter A filter (in Unix) is a program that reads some input, performs a simple translation on it, and writes some output Examples of Unix filters grep sort wc awk vi sed 37 2110313 Operating Systems and System Programs (1/2010)
  • 38. Tutor Session - 2 Text Processing Chulalongkorn University (Cont) Text Processing Commands awk [options] file scan for patterns in a file and process the results grep [options] 'search string' file search the argument (in this case probably a file) for all occurrences of the search string, and list them. sed [options] file stream editor for editing files from a script or from the command line 38 2110313 Operating Systems and System Programs (1/2010)
  • 39. Tutor Session - 2 Text Processing Chulalongkorn University (Cont) Regular expressions Regular expressions come in three different forms • Anchor tie the pattern to a location on the line • Character sets match a single character at a single position • Modifiers specify how many times to repeat the previous expression Regular expressions can be combined to form longer regular expressions 39 2110313 Operating Systems and System Programs (1/2010)
  • 40. Tutor Session - 2 Text Processing Chulalongkorn University (Cont) Regular expressions (Cont) . match any single character except newline * match zero or more instances of single expression preceding it [abc] match any of the characters enclosed [a-d] match any character in enclosed range [^abc]match any character NOT in the enclosed set ^exp regular expression must start at the beginning of the line 40 2110313 Operating Systems and System Programs (1/2010)
  • 41. Tutor Session - 2 Text Processing Chulalongkorn University (Cont) Regular expressions (Cont) exp$ regular expression must end at the beginning of the line treat the next character literally 41 2110313 Operating Systems and System Programs (1/2010)
  • 42. Tutor Session - 2 Other Useful Commands Chulalongkorn University Working With Files cmp [options] file1 file2 compare two files and list where differences occur (text or binary files) cut [options] [file(s)] cut specified field(s)/character(s) from lines in file(s) diff [options] file1 file2 compare the two files and display the differences (text files only) file [options] file classify the file type 42 2110313 Operating Systems and System Programs (1/2010)
  • 43. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) Working With Files (Cont) find directory [options] [actions] find files matching a type or pattern ln [options] source_file target link the source_file to the target paste [options] file paste field(s) onto the lines in file sort [options] file sort the lines of the file according to the options chosen 43 2110313 Operating Systems and System Programs (1/2010)
  • 44. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) Working With Files (Cont) strings [options] file report any sequence of 4 or more printable characters ending in <NL> or <NULL>. Usually used to search binary files for ASCII strings. tee [options] file copy stdout to one or more files touch [options] [date] file create an empty file, or update the access time of an existing file 44 2110313 Operating Systems and System Programs (1/2010)
  • 45. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) Working With Files (Cont) tr [options] string1 string2 translate the characters in string1 from stdin into those in string2 in stdout uniq [options] file remove repeated lines in a file wc [options] [file(s)] display word (or character or line) count for file(s) 45 2110313 Operating Systems and System Programs (1/2010)
  • 46. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) File Archiving, Compression and Conversion compress/uncompress/zcat [options] file[.Z] compress or uncompress a file. Compressed files are stored with a .Z ending. gzip/gunzip/zcat [options] file[.gz] compress or uncompress a file. Compressed files are stored with a .gz ending 46 2110313 Operating Systems and System Programs (1/2010)
  • 47. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) File Archiving, Compression and Conversion tar key[options] [file(s)] tape archiver--refer to man pages for details on creating, listing, and retrieving from archive files. Tar files can be stored on tape or disk. 47 2110313 Operating Systems and System Programs (1/2010)
  • 48. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) Remote Connections finger [options] user[@hostname] report information about users on local and remote machines ftp [options] host transfer file(s) using file transfer protocol rcp [options] hostname remotely copy files from this machine to another machine 48 2110313 Operating Systems and System Programs (1/2010)
  • 49. Tutor Session - 2 Other Useful Commands Chulalongkorn University (Cont) Remote Connections rlogin [options] hostname login remotely to another machine rsh [options] hostname remote shell to run on another machine telnet [host [port]] communicate with another host using telnet protocol 49 2110313 Operating Systems and System Programs (1/2010)
  • 50. Tutor Session - 2 Vi Editor Chulalongkorn University UNIX Editors vi emacs pico Vi is a modal editor (2 modes) Insert mode <i> key • Text insertion Command mode <escape> key • All commands 50 2110313 Operating Systems and System Programs (1/2010)
  • 51. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide Cursor Movement Commands (n) indicates a number, and is optional (n)h left (n) space(s) (n)j down (n) space(s) (n)k up (n) space(s) (n)l right (n) space(s) ^F forward one screen ^B back one screen ^D down half screen ^U up half screen 51 2110313 Operating Systems and System Programs (1/2010)
  • 52. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Cursor Movement Commands (Cont) H beginning of top line of screen M beginning of middle line of screen L beginning of last line of screen G beginning of last line of file (n)G move to beginning of line (n) 0 (zero) beginning of line $ end of line (n)w forward (n) word(s) 52 2110313 Operating Systems and System Programs (1/2010)
  • 53. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Cursor Movement Commands (Cont) (n)b back (n) word(s) e end of word Inserting Text i insert text before the cursor a append text after the cursor (does not overwrite other text) I insert text at the beginning of the line A append text to the end of the line r replace the character under the cursor with the next character typed 53 2110313 Operating Systems and System Programs (1/2010)
  • 54. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Inserting Text (Cont) R Overwrite characters until the end of the line (or until escape is pressed to change command) o (alpha o) open new line after the current line to type text O (alpha O) open new line before the current line to type text 54 2110313 Operating Systems and System Programs (1/2010)
  • 55. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Deleting Text dd deletes current line (n)dd deletes (n) line(s) (n)dw deletes (n) word(s) D deletes from cursor to end of line x deletes current character (n)x deletes (n) character(s) X deletes previous character 55 2110313 Operating Systems and System Programs (1/2010)
  • 56. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Change Commands (n)cc changes (n) characters on line(s) until end of the line (or until escape is pressed) cw changes characters of word until end of the word (or until escape is pressed) (n)cw changes characters of the next (n) words c$ changes text to the end of the line ct(x) changes text to the letter (x) 56 2110313 Operating Systems and System Programs (1/2010)
  • 57. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Change Commands (Cont) C changes remaining text on the current line (until stopped by escape key) ~ changes the case of the current character J joins the current line and the next line u undo the last command just done on this line . repeats last change s substitutes text for current character S substitutes text for current line 57 2110313 Operating Systems and System Programs (1/2010)
  • 58. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) Change Commands (Cont) :s substitutes new word(s) for old :< line nos effected> s/old/new/g & repeats last substitution (:s) command. (n)yy yanks (n) lines to buffer y(n)w yanks (n) words to buffer p puts yanked or deleted text after cursor P puts yanked or deleted text before cursor 58 2110313 Operating Systems and System Programs (1/2010)
  • 59. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) File Manipulation :w(file) writes changes to file (default is current file) :wq writes changes to current file and quits edit session :w!(file) overwrites file (default is current file) :q quits edit session w/no changes made :q! quits edit session and discards changes :n edits next file in argument list 59 2110313 Operating Systems and System Programs (1/2010)
  • 60. Tutor Session - 2 Vi Editor Chulalongkorn University vi Quick Reference Guide (Cont) File Manipulation (Cont) :f(name) changes name of current file to (name) :r(file) reads contents of file into current edit at the current cursor position (insert a file) :!(command) shell escape :r!(command) inserts result of shell command at cursor position ZZ write changes to current file and exit 60 2110313 Operating Systems and System Programs (1/2010)
  • 61. Tutor Session - 2 End Chulalongkorn University Question ? … Answer 61 2110313 Operating Systems and System Programs (1/2010)