Professional Documents
Culture Documents
UNIT 1
i.
ii.
iii.
Lecture Notes
UNIT 1
unique job. But it also provides an option to the user to combine two commands together so that a new job is achieved. For an instance, we can list the contents of the directory by using ls command and count the words, characters and lines in a file by using wc command. These two commands can be combined together by using special characters know as filters. Ex: | (pipe). When we combine ls and wc commands by using | (pipe) like ls|wc, the outcome will be totally different from that off when they are executed individually. In this case, the combined commands will give the count of number of files in your directory. To obtain the count of number of files in a directory, UNIX should a provided one more command, if the facility of the filters were not there? Now by using a single character like | (pipe), we can achieve it very easily. What | (pipe) does is, it takes the output of the first command and gives it as an input for the second command. (ls|wc) So, UNIX provides us to build our own command to achieve a special task by using filters. So we can say UNIX supports building block approach.
iv.
v.
Pattern Matching
As we know ls is the command which is used to list the files available in the directory. Example: $ ls readme chap01 chap02 chap03 helpdir
Lecture Notes
UNIT 1
Suppose if we want to list the files which stars with the filename chap then by using only ls we cant achieve that. So UNIX provides us options of using a special character know as a metacharacter. Example: ls chap* chap01 chap02 chap03
The * is a special character used by the system to indicate that it can match a number of filenames. UNIX also supports regular expressions, which are framed with the characters from the metacharacters set. So, UNIX supports pattern matching concept also.
vi.
Programming Facility
The UNIX shell is also a programming language; it was designed for a programmer. UNIX shell contains all the features, like control structure, loops and variables, which makes UNIX as a powerful programming language. In case of windows, if I have to execute C/C++ or java programs we need to install additional softwares whereas in UNIX it is not necessary to do so, as they come with UNIX operating system.
vii.
Documentation
To know about UNIX in detail there exist many online help facilities like man command. It is the most important reference for commands and their configuration files. Apart from the online documentation, through internet also we can download information regarding UNIX. There are several newsgroups on UNIX, where you can put your queries and get the information regarding that. The FAQ (Frequently Asked Questions) is a document that addresses common problems is also available in net. There are several articles published in magazines and journals and lecture made available by universities on their web site.
Lecture Notes
UNIT 1
The UNIX Architecture:The architecture of UNIX includes two main agencies, kernel and shell; these two handle all the work of the system by themselves. The kernel interacts with machine hardware and the shell with the user.
Kernel:
Kernel is the core (heart or central part) of the operating system; it is a collection of routines written in C language. Kernel will be loaded into memory when the system is booted and communicates directly with the hardware. When the user application wants to access the hardware (hard disk or terminal), they take the help of the kernel, which performs the job on the user behalf. User applications access the kernel through set of functions called system calls (System call is a request made by any application program to the kernel for performing specific task).
Apart from providing the support to user application, the kernel also manages the systems memory, schedules processes, and decides their priority and many more.
Shell:
In UNIX user always interact with kernel through commands. But computer does not have inherent capability of translating those commands into action. So, it requires a command interpreter, i.e., nothing but the shell. Shell is the interface between the user and the kernel.
In a System, there will be only one kernel running on the system, but there can be many shells running, according to user choice.
4
Lecture Notes
UNIT 1
When a user enters a command, the shell thoroughly examines the keyboard input for special characters. If it finds any, it rebuilds a simplified command line and finally communicates with the kernel to make sure that command is executed. Example: - $ echo hello hello hi hi
In the above example, the echo command has some input, which contains lots of spaces between the arguments. While processing, the shell compresses all the multiple spaces in the above command line to a single space. Later echo command runs with spaces compressed and gives the output as hello hi.
File and process:The two major entities that are supported in the UNIX are the file and the process. Files have places and the processes have life.
File:
A file is an array of bytes or it is just a sequence of characters. File acts as container for any information. One file is part of another file by being a part of single hierarchical structure (file system). So as a user, we can locate a file with reference to predefined place. As a user, we can place a file at a specific location in the hierarchy and we can move a file from one place to another. UNIX considers directories and devices also as a file. The dominant file type is text file and the behavior of the system is mainly controlled by the text file.
Process:
Process is program under execution. The process is the name given to a file, when it is executed as a program. A process is a time image of an executable file. Like files, processes also belong to a separate hierarchical tree structure of process as grand parents, parents, children, sliblings and grandchildren and they take birth and die also.
System call is a set of routine exposed to get the kernel service. There will be finite number of system call implementation to any operating system. All UNIX flavored operating system follow the POSIX standard.
5
Lecture Notes
UNIT 1
UNIX operating system may support thousands of commands or applications. But they all use or invoke finite system calls to communicate with the kernel. In windows system, a C programmer uses the standard library functions for everything. As a windows user we cant directly invoke write( ) system call, to add some content into a file. Programmers are forced to use a library function like fprintf for that purpose.
In contrast to above, a C programmer in UNIX system has complete access to the entire system call routines as well as standard library functions.
3. What are internal and external commands in UNIX? Explain three of them each with examples.
External Command
1. External command will have separate executable file in either /bin or /usr/bin directory.
Example: $type ls /bin/ls In the above example type command display the location of ls executable file. In this case, it is stored in the /bin/ls directory.
2. Shell Environment variable PATH will store the path of the directory which contain
executable file.
3. If user invoke any external command, shell will search for invoked command ( related
Internal Command 1. Internal commands are built-in commands of shell. It will not have separate executable file as in external command. Example: $type echo echo is shell builtin
Gangadharaiah S. Arun K. H., Dept. of ISE, AcIT 6
Lecture Notes
UNIT 1
In the above command type command display echo as built-in command instead od displaying the path of executable file as earlier. 2. Shell Environment variable PATH, will not have any path related to internal command. 3. If user invokes any internal command, shell will not search PATH variable. 4. Internal command will not create any new process. Shell process itself executes the internal command. 5. Simple operations (commands) are implemented as internal command.
4. What is the difference between an argument and an option? Explain with examples.
A command is a program that tells the UNIX system to do something. Command with its arguments and options in known as command line. It has the form: $command [options] [arguments]
Command indicates executable program. [argument] indicates on what the command is to perform its action, usually a file or series of files. An [opt ion] modifies the command, changing the way it performs. Commands are case sensitive in UNIX. Example LS and ls are not the same. Options are generally preceded by a hyphen (-), and for most commands, more than one option can be strung together, in the form: $command -[option][option][option] Eg: $ ls -alR Will perform a long list on all files in the current directory and recursively perform the list through all sub-directories.
For most commands you can separate the options, preceding each with a hyphen, $ command -option1 -option2 -option3 Eg: $ls -a -l -R
Some commands have options that require file as parameters. Options requiring parameters (files) are usually specified separately. Eg: $wc c test.c 1265 test.c
Lecture Notes
UNIT 1
wc command will display character, word and line count of a specified file as parameter. Here we have specified test.c as file parameter and c as option. This will display only character count of test.c
These are the standard conventions for commands. However, not all UNIX commands will follow the standard. Some don't require the hyphen before options and some won't let you group options together, i.e. they may require that each option be preceded by a hyphen and separated by white space from other options and arguments.
Section
1 2 3 4 5 6 7 8
SVR4
User Programs Kernels System calls Library function Administrative file format Miscellaneous Games Special files ( in /dev) Administration commands
Linux
User Programs Kernels System calls Library function Special files ( in /dev) Administrative file format Games Macro packages and conventions Administrative commands
Lecture Notes
UNIT 1
All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include: NAME The name of the command or function, followed by a one-line description of what it does. SYNOPSIS In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need. Any thing in [ ] is optional, otherwise it is compulsory. | is used only when there is an only one option either on right or left side of the command. DESCRIPTION A textual description of the functioning of the command or function. EXAMPLES Some examples of common usage. SEE ALSO A list of related commands or functions.
6. What is a file? Explain the different types of files available in UNIX OS? Mention the rules to be followed to name a file.
File is a container for storing the information. All data in UNIX is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the file system. In UNIX there are three basic types of files: 1. Ordinary Files: An ordinary file is a file on the system that contains data, text, or program instructions.
Gangadharaiah S. Arun K. H., Dept. of ISE, AcIT 9
Lecture Notes
UNIT 1
2. Directories: Directories store both special and ordinary files. For users familiar with Windows or Mac OS, UNIX directories are equivalent to folders. 3. Device Files/Special Files: All the devices and peripherals are represented by files. Special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters.
1. Ordinary File: An ordinary file or regular file is the most common type of file. Ordinary
files can be further divided into a. Text File
A text file contains only printable characters. We can view this file with simple text editor. All the programs like c, c++, Perl belongs to this category. Text in each file is end with new line character also called as Line Feed. Linefeed is invisible to user. Only special command like od can display this character.
b. Binary File
Binary file contain both printable and non printable character. It can contain entire range of ASCII ( 0 to 255 ) All object file, executable file. Audio, video, images belongs to binary file. Normal text editor produces unreadable output if user try to display it using text editor
2. Directory File
Directory Files doesnt contain any data of the files it holds. Directory stores only certain details of each file/ folder it holds. A Directory normally contain: Filename and Unique number (inode number) associated which each file. In UNIX, user can't directly update the directory file. Only kernel has write permission to Directory. Whenever users create/delete the file/Folder, respective file/folder name is added with inode number by the kernel in the respective Directory.
Lecture Notes
UNIT 1
Device file will have separate file attribute compare to ordinary file. Operation and behavior of the device file depends on the attributes defined for the file. Most of the system call function which work on ordinary file will also work on device file. E.g. read(), open(), close()
File Name
In Unix File name can have Maximum of 255 characters. File name may contain any ASCII value except NULL and / Control and non printable char is also allowed in filename #@ @#acbe a.b.c.d are valid File Name Prefer to use Only Alphanumeric char and special symbol like . (dot), - (hyphen), _ (underscore) File name are case sensitive compare to DOS. File name may/may not have extension. Even it can have more than one extension. Following are valid file name in UNIX test.c.txt test..c test test.c.java
Avoid using (hyphen) at beginning. Because Z file name will be considered as option. This will force shell to display invalid option to the given command. $cat z In the above example, Shell outputs as invalid option, even though you may have file name with z
7. Explain Absolute Path Name and Relative Path Name with example.
Absolute Path Name
An absolute pathname is the location of a file system object relative to the root(/) directory. All absolute pathnames always begin with a slash (/). With Absolute pathname you have access to complete file system objects such as directories and files. Example: /usr /b in /man is the location of the man command.
In a system, two files can have same name, but can't have same absolute path /home/ajay/Lab1.c /home/suresh/Lab1.c Even though above two files are having same name, they refer to two different file.
11
Lecture Notes
UNIT 1
Commands can also be executed by absolute path name ($/bin/date). But to avoid specifying lengthy path name, path for executable are included in PATH variable of shell.
Relative pathname A relative pathname is just a path that starts from your current directory, and thus, doesn't start with a slash (/) character. For example relative path is: directory.
homeworks/ test1
which refers to a file(test1) in the subdirectory (homeworks) under your current A single dot(.) and two dots(..) Can also be used for relative path. . (a single dot) .. (Two dots) Example: $cd . . $cd . . / . .
Changes to parent Directory Moves to two leve l up
8. What is parent child Relationship? With the help of a diagram, explain the UNIX File system tree.
UNIX file System is organized as Hierarchical File System. The top most directory is root(/ ). Root (/) directory has all the subdirectories of the system under it. Every File or Folder except / should have parent directory in hierarchical file system.
In these parent-child relationships of UNIX file system, the parent is always a directory. Super user will have full permission to access and modify any part of the file system. For super user, /root directory will be the HOME directory. Normal user will not have any permission to access root Directory.
12
Lecture Notes
UNIT 1
Once user log on system, by default they are put under /home directory. Eg: If we have user with the name Akash, then once Akash log on to system, he will be put under /home/Akash.
UNIX File System Tree Most vendors adopted the SVR4 structure of the UNIX file system. But it varies based on distribution. But following are the general directories under the root directory :
Contain Unix commands binary. Path variable always contain this Directory
/sbin and /usr/sbin Normal user can't execute this Only System has permission to Execute this. System admin PATH will display this /etc /dev /lib and /usr/lib /usr/include /usr/share/man Configuration files of the system. Contain device file. doesnt Occupy Space on disk Contain all library files in binary form Contain the standard header file This contains man pages. Each section of man pages are stored in separate directory. /usr/share/man/man1 /tmp /var /usr/share/man/man2
Users are allowed to create temp files. These files are cleaned up regularly Variable part of the file system. Contain print jobs, out going and
13
Lecture Notes
/home
14