Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Unix Operating System

Similar presentations


Presentation on theme: "The Unix Operating System"— Presentation transcript:

1 The Unix Operating System
Course code: 10CS44 UNIT-1 The Unix Operating System Engineered for Tomorrow Prepared by : Thanu Kurian Department :Computer Science Date :

2 What is UNIX? An Operating System (OS) Mostly coded in C
Engineered for Tomorrow An Operating System (OS) 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 History (Brief) 1980’s 1990’s 1969 1970’s System V release 4 TCP/IP
Engineered for Tomorrow History (Brief) 1969 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

4 Why Use UNIX? multi-tasking / multi-user lots of software
Engineered for Tomorrow 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

5 The UNIX architecture and Command Usage
Engineered for Tomorrow The UNIX architecture and Command Usage The UNIX Architecture Kernel and Shell: Kernel: is the core of the OS kernel is loaded into memory when the system is booted and communicates directly with the hardware. user programs access the kernel thru’ a set of functions , called system calls. kernel also manages system’s memory, schedules processes, decides their priorities and performs other tasks.

6 Kernel – shell relationship
Engineered for Tomorrow user user user Contd…. Kernel – shell relationship Other s/w shell shell shell cp cc X window Kernel ls grep Hardware tar Spreadsheets sort Other Compilers ps Databases who sed Text Processors Browsers

7 Shell : Is the outer part of OS
Engineered for Tomorrow Contd…. Is the outer part of OS is the interface between user and kernel there is only one kernel running on the system, but there could be several shells in action – one for each user logged in. acts like command interpreter- it accepts commands issued by the user, interprets these commands, and executes the appropriate programs. Linux uses the Bash shell by default Shell :

8 File and Process: File: Is an array of bytes Hierarchical file system
Engineered for Tomorrow File and Process: File: Is an array of bytes Hierarchical file system Directories and devices are members of file system Dominant file type is text

9 is the job (program) in execution. form a hierarchical tree structure
Engineered for Tomorrow Process: is the job (program) in execution. form a hierarchical tree structure UNIX provides tools to control processes, move them between foreground and background and kill them. System Calls: are the routines (functions) defined in the kernel user to communicate with the kernel thru’ system calls system calls are described in POSIX (Portable Operating System Interface) specification All UNIX systems use the same system calls. e.g. : write, open

10 Features of UNIX: 1. A Multi-user system:
Engineered for Tomorrow Features of UNIX: 1. A Multi-user system: Multiple users working on a single system. The resources (CPU,Memory and hard disk) are actually shared between all users. 2. A Multiprogramming system: Permits multiple programs to run this can happen in 2 ways: i) multiple users can run separate jobs. ii) a single user can also run multiple jobs.

11 3. A Multitasking system:
Engineered for Tomorrow 3. A Multitasking system: a single user runs multiple tasks concurrently. in this environment, one job is running in the foreground , the rest run in the background. 4. The Building-Block Approach: “small is beautiful” is implemented thru’ pipes and filters. by interconnecting a number of tools , we can have a large number of combinations of their usage.

12 Engineered for Tomorrow
5. The UNIX Toolkit: There are general-purpose tools, text manipulation utilities (filters), compilers and interpreters , networked applications, system administration tools and shells. 6. Pattern Matching: The * (called as metacharacter) is a special character used by the system to indicate that it can match a number of files. complex pattern matching can be done with the help of regular expressions.

13 7. Programming Facility: The UNIX shell is a programming language.
Engineered for Tomorrow 7. Programming Facility: The UNIX shell is a programming language. it has control structures, loops and variables. shell scripts are the programs that can invoke the UNIX commands. many of the system’s functions can be controlled and automated by using the shell scripts 8. Documentation: The principal online help facility is the man command it is the reference for commands and their configuration files. there are several newsgroups on UNIX available on the Internet. The FAQ (Frequently Asked Questions) – a document that addresses common problems is also available on the Internet. articles in magazines and journals, lecture notes by universities.

14 Understanding the UNIX Command
Engineered for Tomorrow Understanding the UNIX Command Locating Commands: UNIX is command-based system. the commands are essentially files containing programs , written in C. the commands used by all users are located in /bin and /usr/bin. to know the location of an executable program , use the type command. e.g.: $ type ls ls is /bin/ls when we execute ls command , the shell locates this file in the /bin directory and makes arrangements to execute it.

15 this variable can be evaluated using echo command as follows:
Engineered for Tomorrow Contd…. The PATH variable: The shell variable, PATH, specifies the search list of directories for locating commands. The shell searches through these directories in order whenever it needs to find a command. this variable can be evaluated using echo command as follows: $ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/ccs/bin:/usr/local/java/bin:. Root directory

16 Environment variable:
Engineered for Tomorrow Environment variable: A variable that specifies how an operating system or another program runs, or the devices that the operating system recognizes. set of dynamic values that can affect the way running processes will behave on a computer. A string consisting of environment information, such as a drive, path, or filename, associated with a symbolic name that can be used by MS-DOS and Windows.

17 Internal and External Commands
Engineered for Tomorrow Internal and External Commands An Internal command is built into the shell, and is normally executed even if there's an external command of the same name. e.g.: echo command $ type echo echo is a shell built-in when echo is typed, the shell won’t look in its PATH to locate it (even if it’s there in /bin) , rather executes it from its own set of built-in commands.

18 External Commands exist on disk as separate files.
Engineered for Tomorrow External Commands exist on disk as separate files. e.g.: ls command, exists in the /bin directory (or /usr/bin). Command Structure: A command is used with options and arguments. commands and arguments must be separated by any number of spaces or tabs (whitespace). Options: ls –l note -l is an argument to ls , known as option. An option is normally preceded by a minus sign (-).

19 ls: illegal option – z //message from ls command
Engineered for Tomorrow 2) ls –z note ls: illegal option – z //message from ls command 3) $ ls-l bash:ls-l: command not found 4) ls –lat is same as ls –l –a –t to obtain the same output

20 tput clear // clear is an argument to tput cat list
Engineered for Tomorrow 2. Filename Arguments tput clear // clear is an argument to tput cat list many UNIX commands use a filename as argument, so the command can take input from the file. many commands work with multiple filenames as arguments. e.g.: 1) ls –lat chap01 chap02 chap03 2) cp chap01 chap02 progs // cp copies files 3) rm chap01 chap // rm removes files

21 command line is complete only after user hits [Enter].
Engineered for Tomorrow The command with its arguments and options is known as the command line. command line is complete only after user hits [Enter]. The complete line is then fed to the shell as its input for interpretation and execution.

22 Flexibility of Command usage:
Engineered for Tomorrow Flexibility of Command usage: a command can often be entered in more than one way. 1. Combining commands: UNIX allows to specify more than one command in the command line. each command has to be separated from the other by a ; (semicolon)‏ e.g.: wc note ; ls –l note The combined output of two commands can be sent to the file newlist as follows: e.g.: (wc note ; ls –l note ) > newlist metacharacter

23 2.A Command Line can be overflow or be split into multiple lines:
Engineered for Tomorrow 2.A Command Line can be overflow or be split into multiple lines: Terminal width is restricted to 80 characters. The command simply overflows to the next line though it is still in a single logical line. Sometimes it is necessary to split a long command line into multiple lines. So the shell issues a secondary prompt , usually > , to indicate that command line is not complete.

24 Engineered for Tomorrow
Example $ echo “this is >a three line // A second prompt(>) appears >text message” This is a three line text message

25 3. Entering a Command before previous command has finished:
Engineered for Tomorrow 3. Entering a Command before previous command has finished: Subsequent commands can be entered at the keyboard (as many commands as we wish) without waiting for the prompt. the command that has been entered remains stored in a buffer, maintained by the kernel for all keyboard input.

26 man : Browsing the manual pages online
Engineered for Tomorrow man : Browsing the manual pages online UNIX offers an online help facility in the man command. Man displays the documentation- man documentation ,of every command in the system e.g.: man wc //help on the wc command The entire man page for wc is displayed on the screen. Navigation and Search: Two navigation commands working on all systems are: f or spacebar , advances the display by one screen of text at a time b, which moves back one screen.

27 Understanding a man page:
Engineered for Tomorrow Understanding a man page: A man page is divided into a number of compulsory and optional sections. NAME, SYNOPSIS, DESCRIPTION are 3 common sections. NAME presents a one-line introduction to the command. SYNOPSIS shows the syntax- the options and arguments used by the command. DESCRIPTION provides a detailed description. Using man to understand man: man man // Viewing man pages with man

28 Further Help with man –k, apropos and whatis
Engineered for Tomorrow Further Help with man –k, apropos and whatis man –k: Searches a summary database and prints one-line description of the command. Example: $ man –k awk awk awk(1) -pattern scanning and processing language nawk nawk(1) -pattern scanning and processing language apropos: lists the commands and files associated with a keyword.

29 ftp ftp(1) -file transfer program
Engineered for Tomorrow Example: $ apropos FTP ftp ftp(1) -file transfer program ftpd in.ftpd(1m) -file transfer protocol server ftpusers ftpusers(4) -file listing users to be disallowed ftp login privileges whatis: lists one-liners for a command. $ whatis cp cp cp(1) -copy files

30 Engineered for Tomorrow
When Things Go Wrong

31 The File System The File:
Engineered for Tomorrow The File System The File: Is a container for storing information. (may be a sequence of characters)‏ UNIX file doesn’t contain the eof (end-of-file) mark. A file’s size is not stored in the file , nor even its name. All file attributes are kept in a separate area of the hard disk, which is accessible only to kernel. UNIX treats directories and devices as files as well. All physical devices like hard disk, memory, CD-ROM, printer and modem are treated as files.

32 UNIX treats shells and kernel also as files.
Engineered for Tomorrow UNIX treats shells and kernel also as files. Files are divided into 3 categories: i) Ordinary file: also known as regular file. contains only data as a stream of characters ii) Directory file: contains the file name and its associated inode number. iii) Device file: contains no data but the kernel uses the attributes of the file to operate the device. all peripherals and devices are represented by files.

33 Ordinary (Regular) file:
Engineered for Tomorrow Ordinary (Regular) file: Is the most common file type ordinary file can be divided into 2 types: i) text file ii) binary file Text file: contains only printable characters which can be viewed. text file contains lines of characters where ever line is terminated with the newline character. (linefeed or LF)‏ e.gs: C and Java program files, shell and perl scripts ii) Binary File: contain both printable and unprintable characters that cover the entire ASCII range(0 to 255)‏ e.gs: UNIX commands, object code and executables of C programs, Picture, sound and video files

34 Engineered for Tomorrow
2. Directory File A directory contains no data , but keeps some details of the files and subdirectories that it contains. The UNIX file system is organized with a number of directories and subdirectories. A directory contains the file name and not the file’s contents. There will be an entry for each file in the directory. Each entry has 2 components: i) The filename ii) A unique identification number for the file or directory, called the inode number. When any file is created or removed, the kernel automatically updates its corresponding directory by adding or removing the entry (inode number & filename) associated with that file.

35 The attributes of every file is stored on the disk .
Engineered for Tomorrow 3. Device File: Device files are generally found inside a single directory structure, /dev. The attributes of every file is stored on the disk . The kernel identifies a device from its attributes and then uses them to operate the device.

36 In UNIX, the following characters can be used in filenames:
Engineered for Tomorrow Filename: In UNIX, the following characters can be used in filenames: Alphabetic characters and numerals The period(.), hyphen(-) and underscore(_)‏ A file can have as many dots embedded in its name. A filename can also begin and end with a dot. a.b.c.d.e is a valid filename. UNIX is case-sensitive. chap01, Chap01 and CHAP01 are 3 different filenames.

37 Parent-Child Relationship:
Engineered for Tomorrow Parent-Child Relationship: The file system in UNIX is a collection of all the related files (ordinary, directory and device files) organized in a hierarchical structure. Directories and files have parent-child relationship. The topmost directory is called root, represented by a frontslash(/). The root directory(/) has a number of subdirectories under it. These subdirectories have more subdirectories and files under them. The home directory is the parent of kumar. / is the parent of home and the grandparent of kumar. login.sql is an ordinary file under kumar directory. The visual representation is as shown :

38 root(/)‏ UNIX File System Tree: bin var dev tmp usr home lib stand who
Engineered for Tomorrow root(/)‏ Contd.. UNIX File System Tree: bin var dev tmp usr home lib stand who cat date sharma kumar bin sbin include login.sql progs

39 The HOME Variable: The HOME Directory:
Engineered for Tomorrow The HOME Variable: The HOME Directory: The home directory is created by the system when a user account is opened. e.g.: /home/kumar The shell variable HOME tells the home directory. $ echo $HOME /home/kumar Absolute Pathname: shows a file’s location with reference to the top, i.e., root is simply a sequence of directory names separated by slashes

40 pwd: Checking your current directory
Engineered for Tomorrow pwd: Checking your current directory The pwd (present working directory) command tells you the current directory $ pwd /home/kumar

41 cd: Changing the Current directory
Engineered for Tomorrow cd: Changing the Current directory The cd (change directory) command changes the current directory to the directory specified as argument. $ pwd /home/kumar $ cd progs //change the subdirectory to progs under current directory /home/kumar/progs

42 Engineered for Tomorrow
If we want to switch to /bin directory ,we should use the absolute path name: $ pwd /home/kumar/progs $ cd /bin /bin

43 Engineered for Tomorrow
cd command can also be used without any arguments: $ pwd /home/kumar/progs $ cd // cd used without arguments reverts to the home directory /home/kumar

44 mkdir: Making Directories
Engineered for Tomorrow mkdir: Making Directories Directories are created with the mkdir command. The syntax of this command is: mkdir name of the directory to be created e.g.: a directory new is crated under the current directory as follows: mkdir new A number of subdirectories can be created with one mkdir command as follows: mkdir new dbs doc // 3 directories created

45 e.g.: mkdir pis pis/progs pis/data //creates the directory tree
Engineered for Tomorrow UNIX system lets us create directory trees with just one invocation of the command. e.g.: mkdir pis pis/progs pis/data //creates the directory tree This creates 3 subdirectories –pis and 2 subdirectories under pis. We can’t create a subdirectory before the creation of its parent directory. e.g.: $ mkdir pis/data pis/progs pis mkdir: Failed to make directory “pis/data”; No such file or directory mkdir: Failed to make directory “pis/progs”; No such file or directory

46 Sometimes the system refuses to create a directory: $ mkdir test
Engineered for Tomorrow Sometimes the system refuses to create a directory: $ mkdir test mkdir: Failed to make directory “test”; Permission denied This may be due to following reasons: The directory test may already exist there may be an ordinary file by that name in the current directory If we try to create a directory in /bin , /etc or any other directory that houses the UNIX system files

47 rmdir: Removing Directories
Engineered for Tomorrow rmdir: Removing Directories The rmdir(remove directory) command removes directories. e.g.: rmdir doc //removes the directory doc rmdir can also delete more than one directory in one shot. e.g: rmdir pis/data pis/progs pis //directories are deleted in reverse order

48 shows a file’s location with reference to the top, i.e., root
Engineered for Tomorrow Absolute Pathnames: shows a file’s location with reference to the top, i.e., root is simply a sequence of directory names separated by slashes e.g.: /home/kumar Suppose we are placed in /usr and want to access the file login.sql which is present in /home/kumar, we can give the pathname of the file as below: cat /home/kumar/login.sql

49 No two files in a UNIX system can have identical absolute pathnames .
Engineered for Tomorrow No two files in a UNIX system can have identical absolute pathnames . We can have 2 files with the same name , but in different directories; their pathnames will also be different. Using the Absolute pathname for a command Since date command resides in /bin (or /usr/bin) , we can use the absolute pathname as follows: $ /bin/date Mon Aug 25 09:40:45 IST 2008

50 Engineered for Tomorrow
For any command that resides in the directories specified in the PATH variable, we need not use the absolute pathname. If we want to execute programs residing in some other directory that isn’t in PATH ,the absolute pathname needs to be specified. e.g.: to execute the program less residing in /usr/local/bin , we need to give the absolute pathname: /usr/local/bin/less

51 A pathname which specifies the location of a file using the symbols
Engineered for Tomorrow Relative Pathname: A pathname which specifies the location of a file using the symbols . and .. i.e (single dot) –represents the current directory .. (two dots) –represents the parent directory Assume that we are in /home/kumar/progs/data/text , we can use .. as an argument to cd to move to the parent directory, /home/kumar/progs/data as shown below:

52 Using . and .. in relative path names
Engineered for Tomorrow Using . and .. in relative path names $ pwd /home/kumar/progs/data/text $ cd // moves one level up /home/kumar/progs/data To move to /home , we can use the relative path name as follows: /home/kumar/pis $ cd ../ // moves two levels up /home

53 ls - list directory contents
Engineered for Tomorrow ls - list directory contents The command to list your directories and files is ls. With options it can provide information about the size, type of file, permissions, dates of file creation, change and access. Syntax ls [options] [argument] Common Options When no argument is used, the listing will be of the current directory. There are many very useful options for the ls command. A listing of many of them follows. When using the command, string the desired options together preceded by "-". -a Lists all files, including those beginning with a dot (.). -d Lists only names of directories, not the files in the directory -F Indicates type of entry with a trailing symbol: executables with *, directories with / and symbolic links -R Recursive list -u Sorts filenames by last access time t Sorts filenames by last modification time -i Displays inode number -l Long listing: lists the mode, link information, owner, size, last modification (time). If the file is a symbolic link, an arrow (-->) precedes the pathname of the linked-to file.

54 b block-type special file c character-type special file
Engineered for Tomorrow The mode field is given by the -l option and consists of 10 characters. The first character is one of the following: CHARACTER IF ENTRY IS A d directory - plain file b block-type special file c character-type special file l symbolic link s socket The next 9 characters are in 3 sets of 3 characters each. They indicate the file access permissions: the first 3 characters refer to the permissions for the user, the next three for the users in the Unix group assigned to the file, and the last 3 to the permissions for other users on the system. Designations are as follows: r read permission w write permission x execute permission - no permission

55 Files available during system installation:
Engineered for Tomorrow The UNIX File System: Files available during system installation: /bin and /usr/bin –are the directories where all the commonly used UNIX commands are found. /sbin and /usr/sbin – User will not be able to execute most command in these directories, only the system administrator can. /etc – directory contains the configuration files of the system. User’s login name and password are stored in this directory. /dev – this contains all device files. These files don’t occupy space on disk. /lib and /usr/lib- contains all library files in binary form. C programs are linked with files in these directories.

56 usr/include - contains the standard header files used by C programs.
Engineered for Tomorrow usr/include - contains the standard header files used by C programs. /usr/share/man - man pages are stored here. There are separate subdirectories here that contain the pages for each section. The second group of files are as follows: /tmp – the directories where users are allowed to create temporary fiels. /var – the variable part of the file system. Contains all print jobs and outgoing and incoming mails. /home – on many systems users are housed here


Download ppt "The Unix Operating System"

Similar presentations


Ads by Google