1 / 136

Workshop on Using UNIX: An Introduction Tutorial

Workshop on Using UNIX: An Introduction Tutorial. Workshop Objectives. teach the basic system utility commands to get you started with UNIX. Workshop Materials. Workshop notes: copies of all slides and supplemental materials. Hands-on Exercises. Workshop Contents.

ninamurray
Download Presentation

Workshop on Using UNIX: An Introduction Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Workshop on Using UNIX: An Introduction Tutorial Applied Operating System Concepts

  2. Workshop Objectives • teach the basic system utility commands to get you started with UNIX. Applied Operating System Concepts

  3. Workshop Materials • Workshop notes: copies of all slides and supplemental materials. • Hands-on Exercises Applied Operating System Concepts

  4. Workshop Contents • Log in and log out of a UNIX system • File and directory management • Communicating with others • Background processes • Input and output files • Pipes and filters Applied Operating System Concepts

  5. Workshop Setup tserver 198.77.88.191 Applied Operating System Concepts

  6. Using UNIX: An Introduction Tutorial Applied Operating System Concepts

  7. What This Workshop Covers • Log in and log out of a UNIX system • File and directory management • Communicating with others • Background processes • Input and output files • Pipes and filters Applied Operating System Concepts

  8. UNIX Features • Multi-user and multi-tasking • Hierarchical filesystem • User-selectable command language (shell) • Compatible file, device, and interprocess I/O • X Window system • Network communication services Applied Operating System Concepts

  9. UNIX Compared with other OS • Mature and stable OS • Large user community • Vendor-independent OS • Network-portable window system (X) • Runs on range of hardware (PC - Cray) • Common Open System Environment (COSE) • Engineering WS and Internet servers. Applied Operating System Concepts

  10. UNIX done it first • Multitasking - 1972 • Long file name - 1970 • Right button for menu - 1988 • Multi-user with file protection - 1970 • Almost all OS now support TCP/IP, NFS, WWW, and Java, all of which were developed on UNIX Applied Operating System Concepts

  11. Command-line Based vs GUI • Things can be done beyond what the designers thought of • Search and process text files quickly, ask me about “grep”, “sed”, and “awk” • There is no GUI interface for every thing. Applied Operating System Concepts

  12. Versions of UNIX • AT&T - System V Release 4 • University of California at Berkeley - BSD 4.4 • Xenix • POSIX • SunOS, Solaris • SCO UNIX • AIX • HP/UX • LINUX Applied Operating System Concepts

  13. Connecting to UNIX • Directly connected • console • workstation • dumb terminal • From other systems • telnet / rlogin • X terminal • kermit/procomm Applied Operating System Concepts

  14. Logging in/out • Log in • Connect to the UNIX system • Press ENTER key several times, if needed • At the log in prompt, type your userid (case sensitive) and press ENTER key. • At the password prompt, type your password (case sensitive) and press ENTER key. • Log out • exit or logout • Ctrl-d Applied Operating System Concepts

  15. Changing Passwords • When • First time • Frequently (4~6 months) • How $ passwd • old passwd is required • What password to choose? • more than 6-8 character long • Mixed lower and upper case alphabetical + punctuation • avoid names, dates, numbers, common words, ... Applied Operating System Concepts

  16. user Applications shells Kernel Hardware UNIX Shell • UNIX Shell • user interface to the system • interprets commands • run programs • Types • Bourne (sh), Korn (ksh), C (csh), Bourne Again (bash) • Prompt • “I’m ready and waiting for your command” • usually “%”, “$”, or “>“ • customizable Applied Operating System Concepts

  17. UNIX Command Format <command> <options> <arguments> • First word is the command • The rest, if any, are options and arguments • Commands are case sensitive and mostly in lowercase • A command may or may not have arguments $ date $ ls -l • Arguments are usually files or directories $ ls -al /etc Applied Operating System Concepts

  18. Commands (2) • Options: • single letters • prefixed with a dash “-” • combined or separated (e.g., -al = -a -l) • come before other arguments • Spaces must be inserted between commands, options, arguments • Multiple commands are separated by a semicolon “;” and they are executed sequentially. • Control characters: Ctrl-c, Ctrl-h, Ctrl-z, … • On-line help (man pages) Applied Operating System Concepts

  19. UNIX Filesystem root directory / ... bin etc usr home tmp ... ... ls hosts zoman yusuf badr ... thesis bin mail User home directory ... ch1.tex Applied Operating System Concepts

  20. File and Directory Names • Case sensitive • Any character • Avoid “/”, “>“, “ “, “!”, • they are legal but hard to use with shells • Length: 14 characters • Must be unique inside its directory • Wildcards • “*” any number of characters • “?” any single character • “[ ]” Any one of the characters between the brackets Applied Operating System Concepts

  21. pathnames • pathname: is an address that locates a directory or a file in the UNIX file system. • Absolute pathname: always starts with “/” /home/zoman/thesis/ch1.tex • Relative pathname: never starts with “/” thesis/ch1.tex • Relative pathname up: using “..” ../thesis/ch1.tex Applied Operating System Concepts

  22. Directory Navigation • Moving around $ cd /etc $ cd thesis/fig $ cd .. • Where am I $ pwd /home/zoman • Creating/removing $ mkdir GoodStuff $ rmdir BadStuff Applied Operating System Concepts

  23. Directory Navigation (2) • File listing $ ls - normal list $ ls -a- normal list + plus hidden files $ ls -l- long list $ ls -al- long list + hidden files $ ls -F- normal list + file type Applied Operating System Concepts

  24. access permission owner name group size (bytes) modification date and time # of links type Long Listing Files bash$ ls -l total 306 -rwxr-xr-x 1 zoman zoman 30 Aug 26 1996 ChModAll -rwx------ 1 zoman zoman 50 Aug 26 1996 Dis -rwxr-xr-x 1 zoman zoman 92 Aug 26 1996 MyClean -rwxr----- 1 zoman zoman 156 Aug 26 1996 chksp -rwxr----- 1 zoman zoman 31 Aug 26 1996 d2t -rwx------ 1 zoman zoman 35 Aug 26 1996 dvi2ps -rwxr-x--x 1 zoman zoman 40960 Aug 26 1996 hcal -rwxr-x--x 1 zoman zoman 32768 Aug 26 1996 hdate -rwx------ 1 zoman zoman 21 Aug 26 1996 mps -rwx------ 1 zoman zoman 22 Aug 26 1996 pa -rwxr-x--- 1 zoman zoman 73728 Aug 26 1996 praytime -rwx------ 1 zoman zoman 42 Aug 26 1996 spl bash$ Applied Operating System Concepts

  25. Access Permissions • Access permission on a file control what can be done to the file contents • Access permission on a directory where the file is kept control whether the file can be renamed or removed • To access a directory, access permission should be allowed for all of its parent directories all the way up to the root. Applied Operating System Concepts

  26. rwx r-x r-x Access Permissions • First character shows the file type: • directory (d) • plain file (-) -rwxr-xr-x • The rest, specify three types of users • owner • group • others • who are allowed to • (r) read • (w) write • (x) execute Applied Operating System Concepts

  27. Protecting Your Files • -r-------- (400) protect it from accidental editing • -rw- --- --- (600) only you who can edit/read the file • -rw- r-- r-- (644) only you who can edit, others read • -rw- rw- rw- (666) public file! • dr-x r-x r-x (555) anyone can list but can’t create/delete/rename files • dr-x --- --- (500) only you who do that • drwx --- --- (700) you can do anything but not others • drwx r-x r-x (755) you can do anything, others only list • drwx rwx rwx (777) anyone can do anything! Applied Operating System Concepts

  28. Changing Access Permissions chmod permission files • Character Method $ chmod a=r-x file $ chmod u=rw- file $ chmod ugo+r file $ chmod go-w file • Numerical Method $ chmod 744 file $ chmod 600 file Applied Operating System Concepts

  29. -rwxrwxrwx 111 111 111 -rwxr-xr-x 111 101 101 -rw-r--r-- 110 100 100 -r-------- 100 000 000 owner group others Numerical Access Permissions 777 755 644 400 Applied Operating System Concepts

  30. Viewing and Editing Files • Listing files • cat • head • tail • Listing files page per page • more • less • Editing files • vi • pico • emacs Applied Operating System Concepts

  31. File Manipulation • Copy • cp • move (rename) • mv • remove (delete) • rm Applied Operating System Concepts

  32. Communicating with others • who - who is currently using the system • talk - interactive messaging $ talk user $ talk user@host.anme • e-mail programs • mail - simple and old email program • pine - simple and easy to use email program • elm - powerful email program Applied Operating System Concepts

  33. Input/Output Redirection • Usually programs read from the keyboard and write output and error messages to the screen. • Each running program opens three files: standard input, standard output, and standard error associated with the keyboard, screen, and screen, respectively. • Input can be obtained (directed) from a file using “<“ and “<<“. • Output can be written (directed) to a file using “>“ and “>>“. Applied Operating System Concepts

  34. Piping and Filtering • Consider $ ls /etc > list.temp $ more list.temp $ rm list.temp • Compare with $ ls /etc | more • Piping • directing the output of one command to the input of another • pipe symbol “|”. Applied Operating System Concepts

  35. Piping and Filtering (2) • grep • one of the most useful filters in UNIX. • searches line-by-line for a specified pattern • outputs any line that matches the pattern $ grep “zoman” /etc/passwd $ grep -l “[Zz]oman” .* * • advance filters, check man pages • sed • awk Applied Operating System Concepts

  36. Multi-tasking • Time sharing: many processes running “virtually” at the same time. • Each has a process identification number PID • Viewing processes $ ps $ ps -ef Applied Operating System Concepts

  37. Background vs Foreground Processes • Foreground process • one at a time $ sleep -60 • lock the terminal until it is done • Background processes • one or more can run at the same time in the background • free up the terminal $ sleep -60 & $ sleep -60 Ctrl-z $ bg Applied Operating System Concepts

  38. Canceling/Stopping Processes • Canceling a foreground process Ctrl-c • Killing a background process $ kill pid - get the pid using ps command $ kill -9 pid Applied Operating System Concepts

  39. Customizing Your Account • .profile - ksh, bsh • .login, .cshrc - csh • .bash_profile, .bashrc - bash # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment PATH=$PATH:$HOME/bin ENV=$HOME/.bashrc USERNAME="" export USERNAME ENV PATH Applied Operating System Concepts

  40. Suggested Reading List • Learning the UNIX Operating System Grace Todino, John Strang, and Jerry Peek, O’Reilly Associates, 1994 • A Student’s Guide to UNIX Harely Hahn, McGraw-Hill, 1993 • UNIX Power Tools Jerry Peek, Tim O’reilly, Mike Loukides, and others, O’Reilly & Associates and Random House Electronic Pub. 1993 • UNIX in a Nutshell (System V & Solaris 2.0) Daniel Gilly and staff of O’Reilly Associates, 1992. • The UNIX Programming Environment Brin Kernighan and Rob Pike, Prentice-Hall, 1984 Applied Operating System Concepts

  41. IMPORTANT UNIX Concepts • Environment and Shell Variables • These allow you to customize your UNIX environment • They are different in terms of their SCOPE • SCOPE determines the visibility of a variable Applied Operating System Concepts

  42. Other IMPORTANT UNIX Concepts • Environment Variable • Examples are TERM and DISPLAY • Set a particular variable to a value by using the setenv command • You can print the value of a particular variable or all the environment variable using the printenv command Applied Operating System Concepts

  43. % Environment Variables % • Examples • To set environment variables • % setenv TERM vt100 • % setenv DOG Goofy • print out the terminal type • % printenv TERM • vt100 • print out all environment variables • % printenv Applied Operating System Concepts

  44. Shell Variables • Shell variables are similar to Environment variables except they have a limited scope, i.e., they exist only in the shell which they are defined. • Environment variables on the other hand, exist in all its children shells • To illustrate this concept, let us look at the following example Applied Operating System Concepts

  45. Environment vs. Shell Variables % set prompt = "Parent Shell > " Parent Shell > setenv DOG Goofy Parent Shell > set mouse=Mickey Parent Shell > printenv DOG Goofy Parent Shell > echo $mouse Mickey Parent Shell > xterm & (YOU SHOULD NOW HAVE A NEW xterm WINDOW) THIS IS KNOWN AS “SPAWNING A NEW (OR CHILD) PROCESS” Applied Operating System Concepts

  46. Environment vs. Shell Variables (IN THE NEW xterm WINDOW, DO THE FOLLOWING) % set prompt = "Child Shell > " Child Shell > printenv DOG Goofy Child Shell > echo $mouse mouse: Undefined variable. Applied Operating System Concepts

  47. Environment vs. Shell Variables Child Shell > setenv DOG Pluto Child Shell > set mouse=Minnie Child Shell > printenv DOG Pluto Child Shell > echo $mouse Minnie Child Shell > exit (THE xterm WINDOW SHOULD NOW GO AWAY - THIS PROCESS HAS NOW BEEN KILLED) Applied Operating System Concepts

  48. Environment vs. Shell Variables Parent Shell > Parent Shell > printenv DOG Goofy Parent Shell > echo $mouse Mickey Parent Shell > Applied Operating System Concepts

  49. Environment & Shell Variables Why is this important? UNIX uses Environment and Shell Variables control a number of processes Customizes your working environment Variables used for UNIX Scripts They are typically defined and initialized in your .login and .cshrc files Applied Operating System Concepts

  50. Useful Shell Variables filec#Allows file completion path#List of command directories cdpath#List of candidate directories to cd into history#Number of commands to remember Applied Operating System Concepts

More Related