Unix Notes PDF
Document Details
Uploaded by CooperativeFermat8423
St Joseph's College Echuca
Tags
Summary
These notes provide an introduction to the Unix operating system. They discuss its features, structure, and differences from other operating systems, like Windows. The notes also cover various aspects of Unix, including its components and types of operating systems.
Full Transcript
[ ***INTRODUCTION TO UNIX.***] [Evolution of UNIX]- UNIX System Structure- Features of UNIX- Operating System Services. Architecture of UNIX system, architecture of kernel, features of Kernel. [Definition of operating system]¬ Operating System is the system software that manages computer hardware,...
[ ***INTRODUCTION TO UNIX.***] [Evolution of UNIX]- UNIX System Structure- Features of UNIX- Operating System Services. Architecture of UNIX system, architecture of kernel, features of Kernel. [Definition of operating system]¬ Operating System is the system software that manages computer hardware, software resources, and provides common services for computer programs. [Examples of operating system]¬ Microsoft Windows, UNIX, Linux, MacOS etc [Definition of UNIX]¬ UNIX is a portable, multitasking, multiuser, time sharing operating system(OS) *Founder of UNIX* The UNIX was founded by Ken Thompson, Dennis Ritchie and Brain kerninghan at AT& T Bell Labs research in 1969. *Founder of LINUX* ¬ Linus Benedict Torvalds in 1991 **Expand** IEEE- Institute of Electrical & Electronics Engineers. DOS- Disc Operating System. BASIC- Begineers Automated or All-purpose Symbolic Institution Cycle. FORTAN- Formula Translation COBALT- Common Business Oriented Language. **Difference between UNIX and WINDOWS** UNIX WINDOWS ---------------------------------------------------- ------------------------------------------------- UNIX is an open source(free Windows is not an open source(paid UNIX has very high security system Windows has low security system UNIX is a command based operating system Windows is not a command based operating system The file system is arranged in hierarchical manner The file system is arranged in parallel manner UNIX is not a user friendly Windows is a user friendly Free office(such as excel, PowerPoint and others) Pay for MS Office Low Hardware cost High Hardware cost Customizable add features Not customizable **Features of UNIX** 1. *[Simple design, organization and functioning ]* The architecture of the UNIX is simple, organized and functional. 2. *[Portability]* The code can be changed and compiled on a new machine. 3. *[UNIX Shell]* The user interface UNIX Shell provides the services that the user wants. 4. *[Hierarchical file system ]* UNIX uses a hierarchical file structure to store information. 5. *[Multi user]* UNIX allows more than one user to share the same computer system at the same time. 6. *[Multi-tasking]* More than one program can be run at a time. 7. *[Security ]* UNIX provides high security level( System level security and File level security) 8. *[Pipes and Filters]* In UNIX, we can create complex programs from simple programs. 9. *[Utilities]* UNIX has over 200 utility programs for various functions. 10. *[Machine Independence]* The system hides the machine architecture from the user, making it easier to write applications that can run any computer system. **TYPES OF OPERATING SYSTEMS** 1. Batch Operating System 2. Time-sharing Operating System 3. Distributed Operating System 4. Network Operating System 5. Real Time Operating System 6. Embeded Operating System 7. Mobile Operating System 8. Multi tasking Operating system **Difference between UNIX and LINUX** UNIX LINUX ---------------------------------------------------------------- -------------------------------------------- It is a multi tasking, multiuser operating system It is a free and open source software. Developed by ken Thompson, Dennis Ritchie and Brain Kerninghan Developed by Linus Benedict Torvalds. Source code is not available to general public. Source code is available to general public Not portable Portable Solaris, HP UNIX are some versions. Ubuntu, Fedora are some versions. WhatsApp Image 2024-08-15 at 13.43.38.jpeg *The Architecture of the UNIX system is divided into 4 major components. They are:* 1\) The Kernel 2\) The Shell 3\) Files and Processes 4\) System Calls 1\. The Kernel The Kernel is the heart of the Operating System. It interface between Shell and Hardware. It performs Low Level Task. Eg: Device Management, Memory Managementetc. 2\. The Shell - The Shell is a collection of UNIX Commands. - The Shell acts as an interface between the user and the kernel. - The Shell is a Command Line Interpreter(CLI)--Translates the commands provided by the user and converts it into a that is understood by the Kernel. - Only one Kernel running on the system, but several shells in action-one for each user who is logged in. Eg: C Shell, Bourne Shell, Korn Shell etc. 3\. Files and Processes - A File is an array of bytes and can contain anything. All the data in UNIX is organized into files. A Process is a program file under execution. Files and Processes belongs to a separate hierarchical structure. 4\. System Calls UNIX is written in C. Thousands of commands in the system uses a handful of functions called System Calls to communicate with the kernel. ![WhatsApp Image 2024-08-15 at 13.53.30.jpeg](media/image2.jpeg) - The ***system call and library interface*** represent the border between use programs and the kernel. - The ***File subsystem*** manages files, allocating file space, administrating free space, controlling access to files and retrieving data for users. - ***Kernel Interface to Hardware*** is responsible for handling interrupts and for communicating with the machine. - ***Device drivers*** are the kernel modules that control the operation of peripheral devices. - ***Block I/O devices*** are random access storage devices to reset the system. - ***Scheduler*** module allocates CPU to processes. - ***Memory management*** module controls allocation of memory. - ***Inter-process communication (IPC)*** ranges from asynchronous signalling of events to synchronous transmission of messages between processes. - Directories are organised into a hierarchical structure that fan out like an upside own tree. - The top most directory is known as root and it is written as (/). - The roots contains subdirectory and each of these can contains more subdirectory and so on. WhatsApp Image 2024-08-16 at 22.44.04.jpeg Directory Contents -------------- ----------------------------------------------------------------------------------------------------------------------------- / The root directory /bin Essential low level system utilities /usr/bin Higher-level system utilities and application programs /sbin Super user system utilities(for performing system administration tasks). /lib Program libraries(collection of system calls that can be included in programs by a compiler) for low level system utilities /usr/lib Program libraries for higher level user program. /tmp Temporary file storage space(can be used by any user). /home User home directories containing personal file space for each user.each directory is named after the login of the user. /etc Unix system configuration and information files. /dev Holds the files /device drivers necessary to operate peripherals such as terminals , keyboard,printer,hard disk etc /var Contains files that vary in size,mail directories,printer,spool file,logs etc.. /usr/include Contains standard headed files used by c programs - Owner:It is the owner of the file.the owner's permissions determine what actions the owner of the File can perform on the file. - Group: It gives the name of the group.the groups permissions determine what actions a user,who is a member ofthe group that a file belongs to , can perform on the file. - Other: the rest of the world who are not the owner. the permissions for others indicate what action all other users can perform on the file. - **ls command:** listing files It is used to display all the files and sub directories in a current directory. Synatx : ls options filenames **ls options :** -a : list all files including hidden files. Hidden file names start with a dot character. A single dot (.) refers to the current directory and a double dot (..) refer to the parent Dirctory. -x : list the content in a row -- wise format. -r : list contents,sorted in reverse alphabetical order. \*t : list all files ending with letter t. t\* : list all filnames starting with letter t. -u : list the contents based on the access time or using time. - **cat command:** it is used to i. [Creating files :] cat command can be used to create small files *syntax :* cat options inputfile *Example:* \$cat\>fruits Apple Banana Orange \ or (ctrl+d) ii. [Displaying contents of a file :] cat display only the contents of the file *syntax :* \$cat filename *Ex :* \$cat \> veg Carrot Beans Tomato \< ctrl + d\> \$cat fruits veg Apple Banana orange carrot Beans Tomato iii. [Concatenation of files :] Cat command can concatenate the contents of two or more files and start Store then in another file. *Syntax :* \$cat test1 test2 \> test3 *Ex:* \$cat fruits veg \> food \$cat food Apple Banana Orange Carrot Beans Tomato iv. [Append files : ] Cat command is to append or add data to the contents of the file *Syntax :* \$cat \>\> filname1 *Ex :* \$cat fruit1 Grapes (ctrl + d) - **Cat command:** Cal command is used to print the calender of a required month or year *Syntax :* cal { \[month\] year } *Ex :* \$cal 2013 \| more - **Date and time command:** it displays the current date with time. *syntax :* date options arguments *Ex :* \$date Sat jan 05 15:35:30 1st 2016 - **Who:** Who command provides the login details of all current users in 3 columns format. *Syntax :* Who options ami - **Printf : print formatted output command :** it is used to write formatted output. *syntax :* printf format arguments - **TTY :** terminal command: It is used to known the name of the device file. *Syntax:* Tty *Ex:* \$tty /dev/pts/1 - **Sttycomman:** Set teletype. It will change and print the terminal line settings. *Syntax:* Stty\[-a/g\] \[-f device\] \[settings\] - **Passwd :** It is used to change password in passwd. *Syntax :* \$passwd - **echo :** it is usually used in shell scripts to display messages on the terminal *syntax :* echo options arguments *Ex:* \$echo I am studing in 2 Bca I am studing in 2 Bca - **tput :** reposting cursor command it is used to control the movement of the cursor on the screen. *syntax :* tput options row\_num column \_num - **Bc : calculator command** there are two types of calculator. 1. [ Xcalc :]it is a graphical object which is used only on x- window system and is easy to use. 2. [ bc :] it is a text -- based command. it behaves both as base calculator and a small language.it can perform all arithmetic operations. *Syntax :* bc arguments *Ex:* \$bc \$bc \$bc 15+5 sqrt(49)10/3 20 7 3 21 22 23 - **script command:** it is a unix utility that records a terminal session. *Syntax:* \$script \[options\] filename *Ex*:\$script script started, file is typescript - **Spell command :** Read one or more files and print a list of words that may be misspelled. *Syntax:* \$spell file1 file2 file3 \> file 4 - **Pwd :** print working directory command: Pwd in a command that prints the absolute pathname of your current working directory *Syntax :* Pwd *Ex :* \$pwd /home/rama - **The home directory :** When you log into unix ,your current working directory is your user home directory *The home directory can be found using a shell variable called HOME as shown :* \$ echo \$HOME /home/rama - **Pathnames :** It is the notation used to point to the particular file or directory Pathnames is divided in to two a. Absolute path b. Relative path a. [Absolute path] : Absolute path all ways starts from root directory (/). *Ex :* User /jen /person b. [Relative path] : It points to a file or directory relative to your current working directory. *Ex :* Person /art.html - **Cd-changing the directory** It is used to move from one directory to another.it uses a pathname as its arguments. -.(single dot)means current¬ directory. -..(double dot)means the parent¬ directory. - \~(tilde)means your home directory. - ¬ A plain cd without pathname brings you back to your home directory. [Syntax:] Cd pathname [Ex :]\$pwd /home/rama \$mkdirpartha \$cd partha \$pwd /home/rama/partha - **mkdir:**making directors mkdir command is used to creat new directories. *Syntax:* mkdir optionsdir-names *ex:* \$mkdirranjitha \$cd ranjitha Ranjitha\$ pwd /home/ranjitha - **rmdir:** It removes one or more directories or subdirectories. *Syntax* rmdirdir-names *ex:* \$cd\\ \$rmdirranjitha **[FILE SYSTEM]** The unix file system is organized as a hierarchical tree structure. The structure of a simple unix file system divided into 4 parts. 1\. The Boot block 2\. The Super block 3\. The Inode block 4\. The Data blocks 1\) The Boot Block The boot block is located at the beginning of the file system. - It can be accessed with minimal code incorporated in the computer's ROM bios. - It contains the initial bootstrap program used to load the os. - It is usually a part of the disk label, aspecial set of blocks containing information on the disk layout. 2\) The Super Block It contains statistical information to keep track of the entire file system. - Whenever disk manipulation is required,the super block is accessed. The Super Block contains the following information: 1. Size of the file system: This is the storage size of the device. 2. List of storage blocks: The storage space is divided up into a series of standard size blocks. 3. Number of free blocks on the file system. 4. A list of free blocks with their location. 5. Index to next free block on the list. 6. A list of free inodes. 3\) The Inode Block - Information about each file in the file system is a special kernel structure called an inode. - It contains a pointer to the disk blocks containing the data in the file,information such as type of file,permission bits,the owner and group,file size,file modification and so on. - The name of each file is listed in the directory the file is associated with.A directory is special type of containing a list of filename and associated inodes. - When a user attempts to access a given file by name,the name is looked up in the directory. - Where the corresponding inode is found. An inode for a file contains the following information 1. File owerid : It is the numeric id used in the password file to uniquely identify a user on the system. 2. Group id (GID) :This identifies a group that can be granted special access by the ower. 3. File type :It indicates whether inode represents a file,adirectory,aFIFO,character device. ***[File access permissions ]*** User access: Access by the person who owns the file. Group access: Access by the members of a specified group. Other access: The rest of the world, who are not the owner. *[Types of Access ]* - It contain the actual data contained in the files. - These blocks follows the inode table and occupy most of the storage device space. - It allotted to one file cannot be allotted to another file, unless the two files are linked. - Data in small files can be accessed directly from the inode.¬ - Once read operation features the inode ,and another read features the first data block. - Larger files can be accessed efficiently. - Disk can be filled completely ,with little with wasted space.¬ - Since inode information is kept separetly from data access of data often requires a long¬ seek when files is initially accessed. - Orginal file system uses only 512 bytes blocks, an insufficient transfer size. - Free list quickly becomes scrambled increasing overhead of finding free blocks. ¬ *[Types of Files ]* The unixos is built around the concept of the a file system which is which is used to store all of information. Including the operating sysem kernel itself. There are 4 types of files : 1. Ordinary or Regular files 2\. Directory files 3\. Device files or special files 4\. Hidden files **1. Regular or ordinary files:** It can contain text, data,or program information, files cannot contain other files or directories. Instead use the underscore('\_') symbol.it is ordinary file. An ordinary file can be of 2 types. i. Text file ii. ii\. Binary file I. Text File: A text file contains only printable characters.it contains line of character, each line terminated by a newline character. Ex:text files include c and Java program ,shell and perl scripts. II. Binary File:a binary file contains both printable and unprintable character(0 to 255 ASCII code). Ex:binary files include unix command ,object code of c programs ,pictures,sound,and video files. **2. Directory files:** Directories are containers or folders that holdfiles,and other directories.Directories can point to other directories which are known as Sub directories. The directories generally contains files and other sub directories along with their link information. normally a directory contains 2 pieace of information. i. The file name ii. A unique identification number. When a user creates or remove a file ,the kernel updates the corresponding directory by adding or removing the inode number and filesname associated with the file. **3. Device files :**To provide applications, with easy access to hardware devices.UNIX allows them to be used in much the same way as ordinary files. The video screen of your pc,RAM,disk,input ports and other such devices are usually accessed through device file. Two types of device files in unix - Block-oriented :Block-oriented devices which transfer data in blocks. EX: Hard disk - Character-oriented: Character oriented devices that transfer data on a byte -bybyte basis(eg.modems,printers and networks). **4. Hidden files :**The filename can begin with a dot character is called hidden file. ***[Process management ]*** Process:-Process can be defined as a program under Execution. Unix runs many programs at the same time by using Round-robin Scheduling algorithm. Parent and child process:- In Unix one process can generate another process. The process which generates another process is called Parent process. Newly generated process is called child process. The parent can have one or more children Parent parent Child children Eg:-\$cat fruits \|grep orange fruits The shell creates two child process cat and grep simultaneously. **File access permission (FAP)** There are three types of permission: - Read access - write access - Execute access Read permission :allows users to view the contents of a file and to copy it write permission: allows users to modify the files Execute permission: allows users to run the file, if it is executable. *[Types of users ]* - The owner of the file(user) - The users who belong to the same group as the file(group) - Everyone else (other) File permissions notation - Textual representation like "-rwxr- -r- -" - Numeric(octal) representation like "644" [Textual representation] It is used in UNIX long directory listing.it is consists of 10 character. The first character shows the file type. Next 9 characters are permission, consisting of 3 group: Owner, group , others. Special tools and utilites Each group consists of three symbols : r w x If some permission is denied, then a dash "-"is used instead. File type user permission group permission others permission ----------------- --- --- --- --- --------- --- ----------- --------------- --------------- \-\-\-\-\-\-\-- R w x r \-\-\-- r \-\-\-\-- \-\-\-\-\-\-- \-\-\-\-\-\-- ----------------- --- --- --- --- --------- --- ----------- --------------- --------------- 0 1 2 3 4 5 6 7 8 9 [Numeric representation:] If a numeric representation is used (like in chmod command) then it is in the octal format(base of 8) Octal digits Text equivalent Binary Value Meaning -------------- ----------------- -------------- ------------------------------------- 0 \-\-- 000 All type of access are denied 1 \--r 001 Execute access is allowed only 2 -w- 010 Write access is allowed only 3 -wx 011 Write and execute access is allowed 4 r\-- 100 Read access id allowed 5 r-w 101 Read and execute access is allowed 6 Rw- 110 Read and write access is allowed 7 rwx 111 Everything is allowed ***[Control statements]*** The ability to control the flow of execution of program is known as control statements. The different types of control structures are Sequence control structure Selection control structure Looping control structure ***[Selection control structure]*** This type of instruction allows the shell script to be executed depending on the condition. There are mainly 4 types of decision making instructions. They are - if-then-fi statement - if-then-else-fi statement - if-then-elif-then-else-fi statement case-esac statement if-then-fi statement: in this first check the condition. That condition is true then only the if block statements will be executed otherwise the cursor transfer outside the if condition. Syntax: ex: If\[condition\] if\[\$a-gt 18\] Then then Statement echo"eligible for vote" fi fi **if-then-else-fi statement:** in this first check the condition. That condition is true then only the if block statements will be executed otherwise the else block statements will be executed. Syntax: ex: If\[condition\] if\[\$a-gt \$b\] then then statements echo "a is larger than b" else else statements echo"b is larger than a" fi fi **if-then-elif-then-else-fi statement:** in this first check the condition. That condition is true then only the if block statements will be executed otherwise the cursor checks the next condition then the second condition will be true then inside that statements will be executed and so on. If any conditions were not true then the else block statements will be executed. Syntax: ex: If\[condition 1\] if\[\$a-gt \$b-a\$a-gt \$c\] then then statements echo "a is larger" elif\[condition2\] elif\[\$b-gt \$c\] then then statements echo"b is larger" else else statements echo"c is larger" fi fi **Case-esac statement:** Syntax: case \$variable in \[match1\] statements ; ; \[match2\] statements ; ; \[match3\] statements ; ; : : : : \*) statements ; ; Esac - here match1,match2 etc are the case labels. - When a case statement is evaluated the value of variable is matched in any one of the choices. - When a match is found then shell executes that corresponding match statements. - The pair of semicolon at the end of every choices. It identifies break. - \*) indicates default class. Ex: clear echo "enter a character" Readch case \$ch in \[a-z\]) echo "entered character is lowercase letters" ; ; \[A-Z\] echo "entered character is uppercase letters" ; ; \[0-9\] echo "entered character isdigit" ; ; \*) echo "invalid choice" ;; esac