1 / 166

Introduction to Unix

Introduction to Unix. Course Staff. B.S.Mahanand .B.E.,(M.Tech)., Dept of Computer Science and Engg S.J.C.E. Mysore. Course Texts. Text Book: Unix Concepts &Applications By Sumitabha Das. Reference: Learning Unix - for those who have not used Unix before.

khan
Télécharger la présentation

Introduction to Unix

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. Introduction to Unix

  2. Course Staff B.S.Mahanand .B.E.,(M.Tech)., Dept of Computer Science and Engg S.J.C.E. Mysore. Introduction to Unix

  3. Course Texts Text Book: Unix Concepts &Applications By Sumitabha Das Reference: Learning Unix - for those who have not used Unix before. Introduction to Unix

  4. Operating Systems • An Operating System controls (manages) hardware and software. • provides support for peripherals such as keyboard, mouse, screen, disk drives, … • software applications use the OS to communicate with peripherals. • The OS typically manages (starts, stops, pauses, etc) applications. Introduction to Unix

  5. Single vs. Multitasking • Some old operating systems could only do one thing at a time (DOS). • Most modern systems can support multiple applications (tasks) and some can support multiple users (at the same time). • Supporting multiple tasks/users means the OS must manage memory, CPU time, network interfaces, ... Introduction to Unix

  6. User Interfaces • The User Interface is the software that supports interactions with a human. • Some operating systems directly provide a user interface and some don't. • Windows is an example of an Operating System that includes a user interface. • Unix (the OS) does not directly provide a user interface. Introduction to Unix

  7. What is UNIX? • UNIX is a popular operating system (OS) in both engineering and business world • OS is a “super program” that controls sharing of resources and communication between machines • E.g., Windows, OS/2, VMS, MacOS, UNIX • UNIX is available for all platforms Introduction to Unix

  8. Unix and Users • Most flavors of Unix (there are many) provide the same set of applications to support humans (commands and shells). • Although these user interface programs are not part of the OS directly, they are standardized enough that learning your way around one flavor of Unix is enough. Introduction to Unix

  9. Flavors of Unix • There are many versions of Unix that are used by lots of people: • SysV (from AT&T) • BSD (from Berkeley) • Solaris (Sun) • IRIX (SGI) • AIX (IBM) • LINUX (free software) Introduction to Unix

  10. Unix History and Motivation • The first version of Unix came from AT&T in the early 1970s (Unix is old!). • Unix was developed by programmers and for programmers. • Unix is designed so that users can extend the functionality - to build new tools easily and efficiently (this is important for programmers). Introduction to Unix

  11. Unix History and Motivation • K Thomson and D Ritchie at Bell Labs • Wrote first version in assembly then the next version in C; the first “understandable” OS! • UC Berkeley graduate students • Enhanced with memory management and networking capabilities (BDS UNIX) • UNIX Today: contain both features • Commercial UNIX • Linux Introduction to Unix

  12. Some Basic Concepts • Unix provides a simple interface to peripherals (it's pretty easy to add support for a new peripheral). • Unix includes a basic set of commands that allow the user to view/change the system resources (filesystem, processes, peripherals, etc.). Introduction to Unix

  13. What we will look at • In this course we will learn about: • Unix user accounts • the core set of Unix commands • the Unix filesystem • A couple of special programs called "shells". • A number of commonly used applications: • Window system, text editors, programming tools. Introduction to Unix

  14. The power of Unix is that you can extend the basic commands • We will also look at how to extend the basic functionality of Unix: • customize the shell and user interface. • string together a series of Unix commands to create new functionality. • create custom commands that do exactly what we want. Introduction to Unix

  15. UNIX Services • UNIX facts about programs and files • A file is a collection of data stored on disk • A program is a collection of bytes representing code and data that is stored in a file • When a program is started, it is loaded from disk into RAM. A “running” program is called a process • Processes and files have an owner and a group, and they protected from unauthorized access • UNIX supports a hierarchical directory structure • Files have a location within the directory hierarchy Introduction to Unix

  16. UNIX Services • Sharing resources • UNIX shares CPUs among processes by dividing CPU time into slices (typically 0.1 second) and allocating time slices based on their priorities • UNIX shares memoryamong processes by dividing RAM into equal-sized pages (e.g., 4K bytes) and allocating them; only those pages of a process that are needed in RAM are loaded from disk while pages of RAM that are not accessed are saved back to disk • UNIX shares disk space among users by dividing disks into equal-sized blocks and allocating them Introduction to Unix

  17. UNIX Services • UNIX provides communication mechanism between processes and peripherals • Pipe is one-way medium-speed data channel that allows two processes on the same machine to talk • Socket is two-way high-speed data chanel that allows two processes on different machines to talk • UNIX allows server-client model of communication • e.g., X Window systems Introduction to Unix

  18. UNIX for Users • Basic commands • man, ls, cat, more, page, head, tail, less • mv,cp,rm,ln • pwd,cd,mkdir,rmdir,file • chmod, groups, chgrp • Editing utilities and terminal type • vi, emacs Introduction to Unix

  19. Getting Started in UNIX • Obtain an account and logging-in • passwd: utility for changing password • Shells • A middleman program between you and UNIX OS that executes your commands • Shell commands vs. utilities vs. system calls • Three popular shells: Bourne, Korn, C • Shell has a programming language that are tailored to manipulate processes and files; such program is called shell script Introduction to Unix

  20. Utilities for Manipulating File • mv, cp, rm, ln • move,copy,remove,make links to files mv [-fi] soutce targetFile .. rename source filename mv [-fi] soutceList targetDirectory .. move source files into target directory cp [-fip] soutceFile targetFile .. make copy of sourceFile named targetFile cp [-fip] soutceFileList targetDirectory .. copy source files into target directory cp -rR [-fip] soutceDirList targetDirectory .. copy source files into target directory, and copy the directory structure. rm [-fi] fileList rm -rR [-fi] directoryList ln [-fns] source [target] ln [-fns] sourceList targetDirectory .. make links to sour files into target directory • file - determine file type $ file hello.c hello.c: c program text Introduction to Unix

  21. Utilities for Hanling Directory • pwd, cd, mkdir, rmdir • print working directory • change directory • cd, pushd, popd • make directory • remove directory Introduction to Unix

  22. Vi - Editor • vi is a visual text editor. • Most of you are too young to understand what a non-visual editor might be! • check out the ed editor! • vi shows you part of your file and allows you to enter commands that change something (add new stuff, delete a char or line, etc). Introduction to Unix

  23. vi modes vi has a couple of modes: • command mode: move the cursor around, move to a different part of the file, issue editing commands, switch to insert mode. • insert mode: whatever you type is put in the file (not interpreted as commands). when you first start vi you will be in command mode. Introduction to Unix

  24. Cursor Movement Commands(only in command mode!) h move left one position l move right one position j move up one line k move down one line Your arrow keys might work (depends on the version of vi and your terminal) spacebar also does this Introduction to Unix

  25. More Cursor Movement w move forward one word b move backward one word e move to the end of the word ) move to beginning of next sentence ( move to beginning of current sentence Introduction to Unix

  26. Scrolling Commands CTRL-F scroll forward one screen CTRL-B scroll backward one screen CTRL-D scroll forward 1/2 screen CTRL-U scroll backward 1/2 screen Introduction to Unix

  27. Command that delete stuff x delete character (the one at the cursor) dw delete word dd delete line X delete back one character (backspace) 3x delete 3 characters (any number works) 5dd delete 5 lines (any number works) Introduction to Unix

  28. Changing Text cw change word (end with Esc) cc change line (end with Esc) C change rest of the line rx replace character with 'x' (could be anything, not just 'x') Introduction to Unix

  29. Insert Mode • In insert mode whatever you type goes in to the file. There are many ways to get in to insert mode: i insert before current position a append (insert starting after cursor) A append at end of line R begin overwriting text Introduction to Unix

  30. Ending Insert Mode • To get out of insert mode (back to command mode) you press "Esc" (the escape key). • There is a status line (bottom of screen) that tells you what mode/command you are in. Introduction to Unix

  31. Saving and Exiting ZZ save if changes were made, and quit. :wq Write file and quit :w Write file :w file Write to file named file :q Quit :q! Really quit (discard edits) Introduction to Unix

  32. Searching Commands /text search forward for text ?text search backward for text n repeat previous search N repeat search in opposite direction Introduction to Unix

  33. Other Stuff • Copying and Yanking (Paste) • Remembering positions • Switching files • Repeating commands • Display line numbers • Run Unix commands (for example: emacs) Introduction to Unix

  34. Emacs -Editor • emacs is every bit as cryptic as vi! • emacs allows you to customize it with new commands and keyboard shortcuts. • The emacs commands are written in elisp (a dialect of Lisp), so you need to understand elisp to do serious customization. Introduction to Unix

  35. Emacs meta key • Many emacs commands are invoked with sequence of keystrokes. • Emacs doesn't have modes like vi – you can always enter text (at the current cursor position) or commands. • Many commands start with a special keystroke called the metakey. (others use the control key). • The ESC key is (usually) the meta key. Introduction to Unix

  36. Command List Syntax • The book shows a list of tons of emacs commands. The syntax used to show this list looks like this: C-a C-b (means Ctrl-a , Ctrl-b) M-a M-b (means Esc, a, Esc, b) Introduction to Unix

  37. Important Commands • Exit: C-x C-c • Save file : C-x C-s • Undo: C-x u • Get out of a command: C-g Introduction to Unix

  38. Cursor movement • Cursor keys usually work (it depends on how your terminal is set up and how emacs is configured). C-f: forward (right arrow) C-b: backward (left arrow) C-p: previous line (up arrow) C-n: next line (down arrow) Introduction to Unix

  39. Other stuff in emacs • Move by words, sentences, paragraphs • File handling – save/load file, etc. • Delete char, word, sentence, region • Buffer manipulation (multiple buffers) • Searching, replacing • Automatic indentation (major mode) • Lots more (try the tutorial, read the book!) Introduction to Unix

  40. The Environment The Unix system environment can be set by user System variables: Unix system is controlled by number of shell variables set by system called system variables which can be seen by executing $set command Ex- HOME,PATH,IFS,MAIL,PS1,PS2,SHELL,TERM,LOGNAME Introduction to Unix

  41. .profile : It is the shell script executed during login time. stty : To set the terminal characteristics history :It displays previously executed commands. Introduction to Unix

  42. histsize : Used to store more commands $_ : Stores the last arguments of the last command Changing Directory : ~(tilde) ~ acts as short hand representation of home Directory. Introduction to Unix

  43. UNIX Utilities: man & ls • man • on-line help for UNIX commands man [-s section] word man-k keyword • Man pages are divided into 8 sections • 1. Commands & application programs • 2. System calls, 3. Library functions ... • ls • list files ls [options] {fileName}* Introduction to Unix

  44. UNIX Utilities • ls example $ ls -alFs total 15 1 drwxr-xr-x 2 jaemok mass 512 Mar 2 01:04 ./ 3 drwxr-xr-x 46 jaemok mass 3072 Mar 2 01:04 ../ 5 -rwxr-xr-x 1 jaemok mass 5091 Mar 2 01:04 a.out* 5 -rwxr-xr-x 1 jaemok mass 5091 Mar 2 01:04 hello* 1 -rw-r--r-- 1 jaemok mass 36 Mar 2 01:04 hello.c 5 size in block drwxr-xr-x type and file permission 1 hard-link count jaemok owner mass group 5091 size in bytes Mar 2 01:04 modified time a.out filename • Miscellaneous: date, clear Introduction to Unix

  45. Utilities to List File Contents • cat,more,page,head,tail,less catdisplays contents of files given on command line (or from standard input) to standard output $ cat > heart blah blah blah ^D $ _ moreandpagedisplays contents of files(or input) fitted to rows of terminal, and allows you to scroll. headandtailonly displays given number of lines in the first part or the last part of files(or input). lessis similar to more, but has more functions Introduction to Unix

  46. File Owner and Group Every UNIX process has a owner which is typically the user name who started it • My login shell’s owner is my user name When a process creates a file, its owner is set to the process’ owner UNIX represents the user name as user ID Every UNIX user is a member of a group and an UNIX process belongs to a group • My login shell’s group is my group name (ID) Introduction to Unix

  47. File Permissions • File Permissions (ex: rw-r--r--) • owner: rw-, group: r--, others: r-- • r: read, w: write, x: execute • When a process executes, it has four values related to file permission • a real user ID, an effective user ID • a real group ID, an effective group ID • When you login, your login shell process’ values are your user ID and group ID Introduction to Unix

  48. File Permission Application When a process runs, file permission applies If process’ effective user ID = file owner • Owner permission applies If process’ effective group ID=file group ID • Group permission applies Otherwise, others permission applies Super user’s process automatically has all access rights When creating a file, umask affect permission Introduction to Unix

  49. Effective User and Group ID • A process’ effective user ID • depends on who executes the process, not who owns the executable • E.g., if you run passwd (owned by root), the effective user ID is your ID, not root; then how can it update /etc/passwd file owned by root ? • Two special file permissions • set user ID and set group ID • When an executable with set user ID permission is executed, the process’ effective user ID becomes that of executable; the real user ID is unaffected • File permission of /bin/passwd is r-sr-sr-x Introduction to Unix

  50. Changing File Permissions • chmod • change the permission mode of files chmod [-fR] <absolute-mode> fileList chmod [-fR] <symbolic-mode-list> fileList Introduction to Unix

More Related