Introduction to UNIX Topics. UNIX Logging In Shell Unix

Document Sample
Introduction to UNIX Topics. UNIX Logging In Shell Unix Powered By Docstoc
					                                                                          Topics.
        Introduction to UNIX
                                                       •   Logging in.
                                                       •   Unix Shells and useful shell commands.
                        Ke Liu
                                                       •   File System in Unix.
       http://www.cs.binghamton.edu/~kliu/cs350/       •   Program, Process and Process control.
                Kliu1@binghamton.edu                   •   Inter-process communication.
                                                       •   Compiling and debugging C programs.
                                                       •   Editors.
                                                   1                                                  2




                     UNIX                                              Logging In
• UNIX is multi-user and multi-tasking                 • Enter login name and password !
  operating system.                                    • System password file: /etc/passwd (usually).
• Multi-tasking: Multiple processes can run            • You can change password using the
  concurrently.                                          command: passwd.
• Example, different users can read mails,
  copy files, and print all at once.


                                                   3                                                  4




                      Shell                                            Unix Shells
• After a successful login, the shell program          • Common Shells: Bourne shell, the C shell,
  is run. The default shell of bingsuns: tcsh            and the Korn shell.
• bingsun2% ps                                         • The shell on bingsuns is tcsh (tc shell).
  PID TTY TIME CMD                                     • Users can switch between shells, using the
                                                         commands bash, csh, ksh, sh.
  2159 pts/2 0:00 tcsh
                                                       • Control D (^d) to return back to original
• Shell is a command line interpreter that               shell, or just use the command: exit.
  reads user commands and executes them.

                                                   5                                                  6
         Some shell commands                                    Some shell commands (cont’)
                                                            • pwd: working directory (/u0/users/2/kliu1).
• Most Important command: man (manual                       • ls: list contents of directory
  pages).                                                   • mkdir <dir-name>: make directory
• Help: unix commands, C functions.                         • rmdir <dir-name>: remove an empty directory
• Usage: man <command/function>                             • rm –r <dir-name>: remove a directory with all the
• Try “man man” !                                             contents
                                                            • cd <directory>: change directory, ~/ means your
• Example:
                                                              home directory
  man ls, man passwd, man printf.                           • cp <source> <target>: copy command.
                                                        7                                                         8




   Some shell commands (cont’)                                  Some shell commands (cont’)
• chmod <mode> <filename>: change mode of a                 • rm <option> <filename>: remove files
  file/directory
• ls –l <directory or filename>: long list with details
                                                              e.g.: rm –fr directory/filename
• 9 permission bits: d r w x r w x r w x                    • mv <old> <new>: change the name of a file
• 3 categories: user/group/all.                             • Pipes: Connect the stdout of one command
• Permissions: read/write/execute (r/w/x).                    with the stdin of another command
• E.g.: mode= 644 means r w _ r_ _ r _ _                       e.g.: ls -l | more or ls –l | less
  command: chmod 644 <filename>
• first 3 bits for user. Next group. Next all others.
                                                        9                                                     10




                  File System                                          File System (cont’)
• Hierarchical arrangement of files and directories.        • Pathname: absolute and relative.
• Top level: root or /                                      • Absolute pathname: /u0/users/2/kliu1
  e.g.: cd /
                                                            • Relative pathname: abc.
• . Current directory, .. One level higher directory
  e.g.: cd . No change for it is current directory
  or cd .. Change to parent directory.


                                                       11                                                     12
                       Editors.                                     The easiest editor: pico or nano
•   Different editors: emacs, pico, vi                          •   pico <filename>
•   emacs <filename>                                            •   Full screen editor
•   pico <filename>                                             •   Help on the bottom of the screen
•   vi <filename>                                               •   The nano is an extension to the pico




                                                           13                                                    14




         Basic operations in pico                                          Program & Process
•   Ctrl + v : to move page down                                • Program is an executable file that resides on
•   Ctrl + y : to move page up                                    the disk.
•   Ctrl + o : to save the current buffer                       • Process is an executing instance of a
•   Ctrl + x : to exit with or without saving                     program.
•   Ctrl + g : to get help                                      • A Unix process is identified by a unique
•   Ctrl + r : to open a file                                     non-negative integer called the process ID.
•   Ctrl + w : to find a string in the current buffer           • Check process status using the “ps”
                                                                  command.
•   Ctrl + c : to get the current position in the buffer
                                                           15                                                    16




         Foreground/background                                          Foreground/background
               processes                                                      processes
• A program run using the ampersand                             • Only 1 foreground process for each session.
  operator “&” creates a background process.                      Multiple background processes.
                                                                • Where are background processes used?
• E.g.:
                                                                • All system daemons, long user processes, etc.
  bingsun2% back &
                                                                  e.g. printer-daemon process or mailer-daemon
• otherwise it creates a foreground process.                      process.
• E.g.:                                                         • These processes are always running in background.
  bingsun2% back                                                • Pine is foreground process.
                                                           17                                                    18
            Process Status                                  How to stop a process?
bingsun2% back &                                   • Foreground processes can generally be stopped by pressing
                                                     CONTROL C (^C).
[1] 16488 the process id assigned by system        • Background processes can be stopped using the kill
bingsun2% ps                                         command.
                                                   • Usage: kill SIGNAL <process id list>
  PID TTY TIME CMD                                 • kill -9 <process id list> (-9 means no blocked)
 1973 pts/39 0:01 tcsh                                Or kill <process id list>.
 16488 pts/39 0:00 back                            • If a foreground process is not stopping by ^C, you can
                                                     open another session and use the kill command.

                                              19                                                            20