Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to UNIX.

Similar presentations


Presentation on theme: "Introduction to UNIX."— Presentation transcript:

1 Introduction to UNIX

2 What is UNIX? An Operating System (OS)
Full form of UNIX is UNiplexed Information Computing System (UNICS), later known as UNIX. Mostly coded in C Machine independence It provides a number of facilities: management of hardware resources directory and file system loading / execution / suspension of programs

3 What is UNIX? A portable, multi-tasking & multi-user Operating Environment: Portable: different architectures from embedded devices, your laptop, servers, systems with 100+ CPU... and PS3 Multi-tasking: tens of thousands programs running concurrently Multi-user: hundreds of users using the system at the same time You can have many users logged into a system simultaneously, each running many programs. It's the kernel's job to keep each process and user separate and to regulate access to system hardware, including cpu, memory, disk and other I/O devices. objective: build on their familiarity wiith windows. unix can do what winodws can do, but on a bigger scale. * Portable: Most embedded systems run on UNIX. Can run on embedded chips to thousands of CPUs * Multi-tasking: on machine can run several thousands programs while Window will crash with a few hundreds of programs * Multi-user: For Windows, you can have many accounts on one machine. But only one person can log in at the same time (because the GUI limits it to one person). But for Unix, we are talking about the possibility of hundreds of people logging in at the same time. 3

4 Other Features Uses a simple, uniform file model which includes devices and access to other services in a flexible, hierarchical file system. Written in a high-level language (“C”) making it easy to read, understand, change and port. The command prompt is a simple user process, the Unix shell, which is also a convenient job programming language. Includes support for regular expressions which are convenient for complex searching. 4

5 History (Brief) 1969 1970’s 1980’s 1990’s First UNIX at Bell Labs
The MULTICS Kernighan, Ritchie, Thompson 1970’s Bell Labs makes UNIX freeware Berkeley UNIX (BSD) Bill Joy vi editor, C Shell 1980’s System V release 4 TCP/IP Sun Microsystems Solaris Microsoft Xenix, SCO MIT X-Windows 1990’s GNU, LINUX Stallman, Torvalds

6 Unix History At the same time Ken Thompson wrote a game “space travel” in Fortran to run on GECOS OS (Honeywell 635). The spaceship was hard to control and it was expensive to run. He was told to get the game off his work computer. In those days computer users were tracked and billed by CPU time. CPU time was expensive. It came to upper managements attention that Thompson, Ritchie and others were eating up CPU time playing a game called Space Travel. They were asked to remove it from the main frame. They decided to move it to a smaller computer. In order to do this they had to develop a file system and it had to be portable. Using some of the ideas they’ve discussed Unix was born. 6

7 Unix History Dennis Ritchie developed “B” . Then wrote “C” a compiled language. In 1973 entire OS ported to “C”. 7

8 Linus Torvalds 1991 Linux 0.02 is first released to the public.
1994 Linux 1.0 is released. 8

9 Why Use UNIX? multi-tasking / multi-user lots of software
networking capability graphical (with command line) easy to program portable (PCs, mainframes, super-computers) continued

10 free! (LINUX, FreeBSD, GNU)
popular profitable 1996 Sales: US$34.5 Billion, up 12% not tied to one company active community

11 CLI vs. GUI CLI: Command Line Interface: type declarative commands to tell the computer exactly what you want it to do. Advantage: greater flexibility. GUI: Graphical User Interface: use a pointer to select from menus and other graphical widgets to tell the computer what to do. Advantage: easier to use (for some things).

12 The X Window System (X11) Created at MIT (1984 project Athena)
Primary software for running a GUI on Unix. Handles the communication between the terminal and the server (main computer). You need a “windows manager” to handle how the windows will look on your computer. 12

13 The K Desktop Environment (KDE)

14 GNOME

15 OpenLook Windows Manager (olwm)
15

16 Common Desktop Environment (CDE)
16

17 How Do You Boot Unix? Multi-boot Programs
Windows NT OS loader- select the OS of choice Linux LILO (Linux loader)- the tab key will show Selections. Type the name of the OS to load Grub – Newer versions of Linux (i.e., 9.0) use this loader to choose the OS Other methods to boot- Norton system commander, boot disc, Boot Magic… 17

18 Your Account Each user has their own space called their account.
Type your login ID and password to enter your account. Only if the login ID and password match will you be let in.

19 Login to your Account login: ad You type your ID and RETURN. Password: You type your password and RETURN. It does not appear. $ The UNIX prompt (or similar). You can now enter commands.

20 Logout from your Account
or ^D Press CONTROL and D together exit

21 On-line Help man Manual pages Spacebar to go on; ^C to stop
man gnuchess man man apropos topic Lists commands related to topic apropos game apropos help

22 UNIX Books The Unix Programming Environment, Brian W. Kernighan and Rob Pike. Prentice Hall, Inc., 1984. Sumitabha Das, "Unix : Concepts and Applications" A Student’s Guide to UNIX, Harley Hahn, McGraw-Hill, 1993 A Practical Guide to the UNIX System, Mark G. Sobell, Benjamin-Cummings, 3rd Edition, 1995

23 Kernel-Shell Relationship
Hardware Kernel Compilers Internet Tools Unix Commands Database Packages Other Application/ System Software Shell User

24 The layers of a UNIX system.
UNIX Interfaces The layers of a UNIX system. User Interface

25 Unix System Kernel Three major tasks of kernel: Process Management
Device Management File Management Three additional Services for Kernel: Virtual Memory Networking Network File Systems Experimental Kernel Features: Multiprocessor support Lightweight process (thread) support

26 Block Diagram of System Kernel
User Programs Libraries User Level Kernel Level System Call Interface File Subsystem Inter-process communication Process control subsystem Scheduler Device drivers Memory management hardware control hardware Hardware Level

27 What is Shell? Shell is Presents each user a prompt,
Interprets commands typed by user, Executes users commands, Provides user/programming environment, Command Interpreter that turns text that you type (at the command line) in to actions.

28 The Shell The UNIX user interface is called the shell.
The shell does 4 jobs repeatedly: display prompt read command execute command the shell process command

29 Types of Shells Interactive vs. Non-interactive; login or not
Interactive login shell started after login Non-interactive shell Present when shell script is running Just inherits parent’s environment Interactive non-login shell started Started from a command line Copies parent environment then invokes ~/.bash_rc (or ~/.cshrc or ~/.tcshrc)

30 Popular Shells sh Bourne Shell ksh Korn Shell
csh,tcsh C Shell (for this course) bash Bourne-Again Shell

31 Flavors of Unix Shells Two main flavors of Unix Shells To check shell:
Bourne (or Standard Shell): sh, ksh, bash, zsh Fast $ for command prompt C shell : csh, tcsh better for user customization and scripting %, > for command prompt To check shell: % echo $SHELL (shell is a pre-defined variable) To switch shell: % exec shellname (e.g., % exec bash)

32 Families of Shells

33 Typing Commands Try these: date cal who ls -a man cal clear

34 Don’t forget your Best Friend
% man command (e.g., % man ls) shows information about the command usually space or Enter for more information q to quit % man man

35 Changing your Password
The command is: passwd It will ask you for the new password twice.

36 Date Commands date Gives time and date cal Calendar cal 1997 cal 3

37 You and the System uptime Machine’s ‘up’ time
hostname Name of the machine whoami Your name who

38 Calculators expr e Simple arithmetic expr 3 + 5 + 7
bc Programmable Calculator

39 Some General Purpose Commands

40 Redirection, pipes , processes
Output can be redirected to a file with‘>‘: ls > dir.txt cal 2004 > year2004 Output can be appended to a file with ‘>>‘ cal 2004 > years cal 2005 >> years Pipes : sending the output of one program to the input of the other ls | sort who | sort Processes : Running two commands sequentially locate mj > xxx; date locate usr > xxx &

41 The UNIX File System

42 The File Ordinary Files Directory Files Device Files

43 Architecture of Unix Unix file system
root (/) bin usr etc dev var home tmp bin spool log X11R6 (users’ accounts) mail (users’ mail) 43

44 The Parent Child Relationship
A simplified UNIX directory/file system: / etc bin usr1 dev tmp . . . . . . . . . date . . . faculty cal mj

45 File directories In Windows : C:\Documents and Settings\user\ In Unix: /home/n/user Directories in Unix are just like your folders in Windows explain home directory - a directory that is your home. 45

46 Some System Directories
/ root directory /bin commands /etc system data files (e.g. /etc/passwd) /dev files representing I/O devices

47 Typical Directories / : Root of the tree. Where it starts.
bin, sbin, usr/bin: software for the shells and most common Unix commands. dev: short for devices, holds the files necessary to operate peripherals such as printers and terminals. home: contains the home directories of users (/export/home on sun computers). 47

48 Typical Directories tmp: holds temporary files.
var: contains files that vary in size; (Mail directories, printer spool files, logs, etc.) etc: administrative files such as lists of user names and passwords. 48

49 File and Directory Name Rules
Valid names can be made up of: Uppercase letters (A to Z). Lower case letters (a to z). Case sensitive!!! Numbers (0 to 9). Period (.), underscore (_), commas (,). Should not contain spaces or the following: & * \ | [ ] { } $ < > ( ) # ? ‘ “ ; ^ ! ~ %. Never /. You should avoid naming files or directories with Unix commands. 49

50 Pathnames A pathname is a sequence of directory names (separated by /’s) which identifies the location of a directory. There are two sorts of pathnames absolute pathnames relative pathname

51 Absolute Pathnames The sequence of directory names between the top of the tree (the root) and the directory of interest. For example: /bin /etc/terminfo /export/user/home/ad /export/user/home/s /proj1

52 Relative Pathnames The sequence of directory names below the directory where you are now to the directory of interest. If you are interested in the directory proj1: proj1 if you are in s s /proj1 if you are in home home/s /proj1 if you are in user

53 Commands and Pathnames
Commands often use pathnames. For example: /usr/games/fortune cat /etc/passwd List the password file

54 Moving between Directories
s ’s home directory: s proj1 proj2 hobby.c . . . . . .

55 If you are in directory s3910120 how do you move to directory proj1?
cd proj1 You are now in proj1. This is called the current working directory.

56 Move back to directory s3910120 (the parent directory):
pwd Print name of current working directory Move back to directory s (the parent directory): cd ..

57 When in proj1, move to proj2 with one command:
cd ../proj2 ../proj2 is a relative pathname

58 Special Directory Names
/ The root directory . The current working directory .. The parent directory (of your current directory)

59 Examples cd / Change to root directory cd ~ Change to home directory
cd (Special case; means cd ~) cd ../.. Go up two levels.

60 Investigate the System
Use cd cat file List file cd /etc cat passwd ls Directory listing ls List current dir. ls /etc List /etc

61 Making / Deleting / Renaming Directories
Usually, you can only create directories (or delete or rename them) in your home directory or directories below it. mkdir Make a directory rmdir Delete a directory mv Rename a directory

62 Permissions ls –l /etc/passwd read, write, execute (r w x)
-rw-r--r root root Jul 28 16:19 /etc/passwd read, write, execute (r w x) rw- r-- r-- directory owner group everyone chmod -w, +w ….

63 Commands to work with files
cat > filename less head tail cp mv rm wc grep spell ispell

64 Directories, Files and Inodes
Every directory and file is listed in its parent directory. In the case of the root directory, that parent is itself. A directory is a file that contains a table listing the files contained within it, giving file names to the inode numbers in the list. The information about all the files and directories is maintained in INODE TABLE An Inode (Index Nodes) is an entry in the table containing information about a file (metadata) including file permissions, UID, GID, size, time stamp, pointers to files data blocks on the disk etc.

65 Users, Groups and Access Permissions
In UNIX/LINUX, there is a concept of user and an associated group The system determines whether or not a user or group can access a file or program based on the permissions assigned to them. Apart from all the users, there is a special user called Super User or the root which has permission to access any file and directory

66 Access Permissions There are three permissions for any file, directory or application program. The following lists the symbols used to denote each, along with a brief description: r — Indicates that a given category of user can read a file. w — Indicates that a given category of user can write to a file. x — Indicates that a given category of user can execute the file.

67 Access Permissions Each of the three permissions are assigned to three defined categories of users. The categories are: owner — The owner of the file or application. group — The group that owns the file or application. others — All users with access to the system.

68 Access Permissions One can easily view the permissions for a file by invoking a long format listing using the command ls -l. For instance, if the user juan creates an executable file named test, the output of the command ls -l test would look like this: -rwxrwxr-x 1 juan student 0 Sep 26 12:25 test

69 Access Permissions The permissions for this file are listed are listed at the start of the line, starting with rwx. This first set of symbols define owner access. The next set of rwx symbols define group access The last set of symbols defining access permitted for all other users.

70 Access Permissions This listing indicates that the file is readable, writable, and executable by the user who owns the file (user juan) as well as the group owning the file (which is a group named student). The file is also world-readable and world- executable, but not world-writable.

71 Listing the Content of a Directory
ls is used to list the contents of a directory. If the command ls is written with parameter –l then the command lists contents of the working directory with details. Example: $ ls –l

72 Moving in Directories cd try_it Changes the directory to try_it
pwd Prints present working directory (e.g. /home/smith/try_it) cd .. Move to superior directory pwd : Prints /home/smith cd /home The absolute path pwd : Prints /home cd The system is returned to the user home directory pwd : Print /home/smith

73 Make Directory The command mkdir my_dir
makes new directory my_dir (the path is given relative) as a subdirectory of the current directory.

74 Remove Directory The command rmdir your_dir
removes directory your_dir if it is empty.

75 Copy File The command cp file_1 file_2
copies file_1 to file_2. The both files must be in the same working directory. If they are in various directories, the path must be given.

76 Rename and/or Move the File
The command mv file_1 file_2 moves file_1 to file_2 The both files must be in the same working directory. If they are in different directories, the path must be given. The file_1 is removed from the disk.

77 Remove File The command rm file_a removes the file_a from the system
If you use wildcard. For example rm h*c you will remove all files beginning with h and ending with c which are in working directory. If you write rm * you will erase all files from your working directory.

78 Access Permission of File/Directory
The ownership of the file or directory can be changed using the command chown <owner> <file/directory name> The group of the file or directory can be changed using the command chgrp <group> <file/directory name> The permissions of the file can be changed using chmod command chmod -R ### <filename or directory> -R is optional and when used with directories will traverse all the sub-directories of the target directory changing ALL the permissions to ###.

79 Access Permission of File/Directory
The #'s can be: 0 = Nothing 1 = Execute 2 = Write 3 = Execute & Write  (2 + 1) 4 = Read 5 = Execute & Read (4 + 1) 6 = Read & Write (4 + 2) 7 = Execute & Read & Write ( )

80 Communicating with People

81 Information on Others users Who else is logged on?
who Information on current users ps What are people doing? ps -au

82 Examine password info:
w What are people doing? w -sh A shorter report Examine password info: more /etc/passwd grep s38 /etc/passwd

83 Fingering People finger Info. on current users
finger -l Longer information finger user Information on user (need not be logged in) finger ad

84 finger @machine-name User info. for that machine finger @catsix
ping machine-name Is machine alive (on)? ping catsix (^C to stop)

85 Your Finger Information
chfn Change your finger entry finger also prints the contents of the .plan and .project files in your home directory. List ‘.’ files with: ls -a

86 Talking Get out by typing ^C talk user Talk to user (on any machine)
talk ad talk Get out by typing ^C

87 write user Send a message to user on this machine
write ad mesg n Switch off talk / write acceptance. mesg y Switch on

88 Sending E-mail Send mail : mail Add
Subject: Shoe Problem What colour are my shoes? I cannot see them at the moment because of my desk. - Jim ^D

89 The vi Editor Two modes Append a
Insert i Command <ESC> Append a Replace character r, Replace word R ….. Deleting character x, Deleting line dd Exit Goto command mode press :wq ……

90 Filters The UNIX programs that read some input, perform a simple transformation on it and write some output. grep, egrep, fgrep tr, dd, sort Sed, awk – programmable filters

91 grep grep options pattern format filename(s) Some option
-c Counting number of occurrences -n Line numbers along with lines grep Mamata –e mamata database grep [Mm]amata database

92 grep : Regular Expressions
Character sets [mM] , [aeiou] , [a-zA-Z0-9] Immediately preceeding character G*, [gG]* Matching a single character 2… A four character pattern starting with 2 .* A number of characters or none

93 grep : RE Specifying pattern boundaries c
Any non-special character c matches \c Turn off any special meaning of character c ^ Beginning of line $ End of line . Any single character […] Any one of character in …; ranges like a-z are legal [^…] Any single character not in …; ranges are legal r* Zero or more occurrences of r r1r2 RE r1 followed by RE r2 Specifying pattern boundaries ^r pattern beginning with expression r ^[^r] pattern not beginning with expression r r$ pattern ending with expression r

94 egrep : Regular Expressions
r+ : one or more occurrences of r r? : zero or more occurrences of r r1|r2 : r1 or r2 (r) : nested r

95 fgrep Searches for multiple patterns
Does not accept regular expression Multiple patterns are separated by new line character. The disadvantage of grep family is that none of them has a separate facility to identify fields.

96 sort -f : eliminates distinction between uppercase and lowercase letters. -n : numeric comparison - r : largest to smallest +m : comparison skips first m fields +0 : beginning of the line -u : discard duplicates

97 comm File comparison command Gives three columns of the output
Lines that occur only in file 1 Lines that occur only in file 2 Lines that occur in both One or more columns can be suppressed Comm –12 f1 f2

98 tr Transliteration of character in the input
tr a-z A-N Mostly used for character conversion

99 Assignment Try all the UNIX commands. Store the output in a file appropriately using redirection operators. Read a word from the terminal and check if the spelling is correct. Suggest few alternatives. Create a file using Vi. Store few names in the file. Search all the names containing the letter M or m. Create another file using cat command Compare both the files to find the differences Use calculator commands to compute 5 arithmetic expressions.


Download ppt "Introduction to UNIX."

Similar presentations


Ads by Google