1 / 22

Introduction to UNIX (1)

Introduction to UNIX (1). What is UNIX? UNIX Philosophies UNIX for Nonprogrammers. 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

ashanti
Download Presentation

Introduction to UNIX (1)

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 (1) • What is UNIX? • UNIX Philosophies • UNIX for Nonprogrammers

  2. 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

  3. 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

  4. 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

  5. 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

  6. UNIX Services • Utilities • UNIX has more than 200 small utility programs • Editors, compilers, GUI, Shells, text-processing tools • Programmer Support • UNIX is an open (source) system, so its features are available to C programmers through system calls • Standards • UNIX includes two main versions: • System V UNIX from Bell Labs • BSD UNIX from UC Berkeley • HP-UX, Solaris, IRIX, AIX are all based on System V but includes all nice features of BSD as well

  7. Philosophies of UNIX • How UNIX utilities should be written • A UNIX utility should do one thing and do it well, and complex tasks are done by combining these small utilities • e.g., They made the pipe mechanism for combining (e.g., who | sort) data data sort who terminal

  8. Philosophies of UNIX • Unix philosophy of solving problems • Solve it by combining multiple existing utilities using pipe if possible; otherwise • Ask people on the network if they know how to solve it. If they do, great; otherwise • Write some utilities that can aid you solve the problem and add them into UNIX repertoire • Write a C or C++ program to solve the problem

  9. (Brief) History of UNIX • 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

  10. 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

  11. 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

  12. 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}*

  13. 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

  14. 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

  15. 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

  16. Utilities for Hanling Directory • pwd, cd, mkdir, rmdir • print working directory • change directory • cd, pushd, popd • make directory • remove directory

  17. 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)

  18. 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

  19. 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

  20. 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

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

  22. chmod • absolute-mode is octal number if you want a file to have permission setting: rwxr- x--- then, it is an octal number o750 (111 101 000) $ chmod 750 myfile • symbolic-mode-list is comma-separated list of symbolic expressions of form [who] operator [permissions] who : characters u,g,o,a operator : -,=.+ permissions : r,w,x,s $ chmod g-rx myfile

More Related