Unit - 2 OS With Linux - UNIX
Unit - 2 OS With Linux - UNIX
Unix Architecture
Unix Architecture
The core part of unix structure is hardware. Kernal can directly
communicate with hardware. Above kernal, there is a shell to perform
applications such as database packages, internet tools, compilers, system
softwares & unix commands.
(1) KERNAL:
The kernel is the heart of OS. The kernel can directly communicate with
hardware. Kernal works as an interpreter between hardware & shell.
There are 2 most basic functions of kernel.
1. process management
2. resource management
It allocates the resources to process, manage process scheduling and
manage system calls and communicates with hardware. Thus, it hides the
complexity of hardware to user.
Shell
User can not directly communicate with hardware. User
communicate with shell.
Shell analyses the user’s commands & its arguments &
convert it into language which the kernel can
understand.
Shell also provides programming facilities, in which
user can write the shell scripts. This shell script
contains shell commands to perform specific task.
Features of unix
1. multi user
2. multi tasking
3. portable
4. pattern matching
5. tool kit
6. programing facilities
7. system call & libraries
8. Windowing system
9. documentation
10. networking
11. organized file system
12. device independence
(1) multi user.
Unix allows multiple users to concurrently share the resources like
main memory, processor or hard disk. Each user gets equal
opportunity to use resources by allocating a specific amount of time
for each user.
(2) multi tasking:
This feature allows more than one task to run concurrently.
(3) portable:
Unix is developed using a higher level language. So, it is not
dependent on hardware design and its architecture. If unix system
is developed on one system, it can easily be implemented on
another system.
(4) pattern matching:
There are several meta characters used for pattern matching like
*,?,[],^,! Etc.
(5) Tool kit:
Unix provides built in tools for various applications like
database applications, filters, file compression,
communication with other users and various file
management applications.
(6) programming facility:
Unix provides necessary programing facility like case
structure, control structure, loops, condition checking etc.
(7) system call & library:
Like any other programing language, unix provides
system calls and a built in set of library with various
commands. Communication with kernal is called system
call.
(8) windowing system:
Unix provides GUI which allows multiple applications to
run in separate windows. It provides symbols, menus,
buttons etc.
(9) Documentation:
user can get complete information about any commands, its
usage, option, behavior, author of this command &
description of commands in detail.
(10) networking :
Networking allows multiple user to login to the system.
Access system resources like files, devices, database etc.
users can communicate with each other & share their
information.
(11) organized file system:
Unix has its own directory structure, where each
directory contains specific files. For example, bin
directory contains software, dev directory contains
device files.
(12) device independence:
Every device is treated as a file in Unix. Using this
feature, we can get inputs from devices or files and also
sends output to any devices or files.
File structure of unix
ROOT
DEV
◦ This directory includes files for device such as printer, terminal, etc.
ETC
◦ It contains various administrative files such as list of usernames & passwords.
USER
◦ It contains home directories of all users.
HOME
◦ It contains files & directories of logged in (current) user.
TMP
◦ It is used to store temporary files.
VAR
It includes files that contains information that varies frequently.
File & directory permissions
Permission includes 3 permissions.
1. read (r)
2. write (w)
3. execute (x)
When we use long listing command (ls –l), we can see
permissions for each file & directory.
Among first 10 characters, first character identifies file or
directory. Remaining 9 characters shows the permissions.
For exa : rwx
Rwx rwx rwx
User group others
We can change these permissions using chmod command.
Log in commands
1. who
It displays all the users who are currently logged into
system. It returns user name, terminal & login time of
each user.
Syntax : who [options]
-h : shows the header of each column.
-u : shows the idle time of each user.
This command is generally used to monitor that the
terminals are utilized effectively and identify the
activities of user and their idle time.
2. Who am i
It displays only information about currently logged in
user.
Example : who am i
3. passwd
This command is used to change the password .
First, it ask for old password. If It is correct, then ask
for new password.
Syntax : passwd
◦ Old password ******
◦ New password *****
◦ Re – enter new password *****
◦ -d : deletes user’s password
◦ -e : expires an account’s password
◦ -s : display account status information.
Rules for Password
Minimum length 3 characters & maximum length is
255 characters.
Must contains at least 1 numeric or special char within
first 8 characters.
Must contains 2 alphabets.
Must not be based on directory name.
Must not be same as old password.
Must not be same as log in id.
Passwords are case sensetive.
4. Log out
To terminate the session and quit the current user login.
Syntax : logout
File & directory related commands
Ls(list):
It shows the list of files & directories in current directory.
Syntax : ls [options] [file name]
-l : display long listing.
-d : display name of working directory.
-ld : long list of working directory attributes.
-nd : display user group id with long list.
-lt : sorts files according to last modification time.
-p : used to identify directory & files.
cat
It is used to display contents of file. It is also used to create a new
file and append to file.
Options:
-r: recursive removal. Means, removes whole directory
with files.
-f : force removal.
Rmdir (remove directory):
It is used to remove directories. if directory contains the
files, it can not be removed. First, files & sub
directories have to be removed.
Syntax : rmdir directory_name
Tail :
This command is used to display bottom lines of file.
If no argument is specified, it displays 10 lines from
bottom of file.
Syntax : tail –n filename
Touch :
This command is used to change last modification time
and last access time of given file.
By default, it changes both time.
Syntax : touch [option] filename
Options:
-a : change last access time
-m : change last modification time
Vi editor
Introduction :
Unix provides editors to process the contents of files containing
text, source code, or shell programs.
There are 2 types of editors: (1) line editor and (2)screen editor.
Vi is a screen editor, which displays a part of file on the screen. Vi
editor was developed by William Joy at university of California,
Berkeley.
Following things need to be remembered while using vi editor.
(1) commands are case sensitive.
(2) commands are not seen by user on screen while typing.
(3) commands do not require “enter” after command is typed.
Vi editor is generally used to edit text file or shell
scripts. It copies file to buffer, and this buffer is
displayed on the screen. The addition, deletion or
modifications are done in this buffer.
When user save the file, this edited buffer is copied to a
permanent file. If already exists, the previous contents
are overwritten by new buffer contents.
Vi editor is used to invoke vi editor for creating a new
for creating a new file or opening an existing file.
Syntax : vi filename
Switching the modes of vi editor
There are 3 modes of vi editors:
I,a,r,o,s : (colon)
input command exit
Esc Enter
(1) command mode:
Initially when user opens a file in vi editor, it is command
mode. Which contains name of file, number of lines, number
of characters entered in file are displayed in left bottom side,
and cursor is placed top left corner of file.
If user press any key, it is considered as a command. Entered
command will not display, only changes can be seen.
Here, user can not enter or modify the text, but only can move
cursor or delete the text.
Entered character will be considered as command, and execute
automatically. Means, enter key is not required.
To enter some text or modify, user has to enter in input mode.
(2) Input mode:
To enter into input mode, any of characters from
I,a,r,o,s or insert key is used.
Now, user is able to enter or change the text of file.
After completion, if user wants to switch from insert
mode to command mode, “escape (Esc)” key is used.
(3) Exit mode
This exit mode is also known as last line mode. To
enter in this mode from command mode, type (:) colon.
The cursor will move to left bottom of the screen.
Here, after writing exit command, press enter to exit vi
exit mode, and user moved to command mode.
Following list shows different exit commands
Commands Meaning use
:q Quit Exits vi editor. But if there have
been changes made, it will give
warning message.
:q! Quit without saving Exit editor without saving changes
made to file.
:w Save file Write contents of file from buffer to
file without quitting vi editor.
Second Third
First command o/p i/p o/p i/p
command command
Finding patters of file:
Regular expression:
Regular expression is a pattern that describes a set of
string which can be constructed by using various
operators to combine smaller expression.
Expression + operator = regular expression
These regular expressions are used for finding different
patterns of file. Followings are 3 file finding patterns.
(1) grep
(2) fgrep
(3) egrep
(1) Grep
(Global Regular Expression Print)
Grep means globally search for regular expression and print
matching lines.
This command searches for a pattern in one or more text files. It
scans files line by line for finding patterns.
For example : grep ch myfile
Here grep search fro the expression “ch” in myfile. It scans line
by line, and if matches to “ch”, then it displays that line on
standard output.
Syntax grep [option] regular_expression filename
Options :
-i : ignoring case
-c : counting occurrence
-l : display file names
-n : display line numbers
(2) Fgrep (Fixed grep)
It is known as fast grep. It is used for multiple string
searching. It accepts mltiple patterns from command
line.
Syntax : fgrep [option] [pattern] [file]
Fgrep searches for a string and prints all lines that
contain that string.
Fgrep is different from grep & egrep, because it
searches for string, instead of searching for pattern
matches in expression.
(3) Egrep
(Extended Grep)
The egrep utility searches files for a pattern of
characters and prints all lines that contains that patterns.
Regular expression with following symbols are used
with egrep.
+ : matches one or more occurrence of regular
expression.
? : matches one occurrence of regular expression
| : matches string with any of regular expressions.
Working with columns & fields
Cut :
Cut command is basically used for extracting vertical
columns or set of characters either from standard input
or file.
Cut command looks for character positions, specified
by option –c.
For example, following stud.txt file contains data like
file
Syntax : tee [option] filename
Options:
-a appends output to existing file
Example : who | tee userlogin.txt | wc -l
Script :
Cron:
Cron command is used to execute command at specified time
interval.Cron wakes up periodically and executes command.
At & batch executes command only one time. Cron executes process at
regular interval.
After executing the command, during that minute, cron goes to sleep
and again wakes up next minute.
Cron file contains following information with 6 fields.
Cron minute hour dayofmonth month dayofweek
0-59 23 1-31 1-12 0-7
Options:
-l : to view contents of cron file.
-r : to remove cron file.
Wait :
Wait command is used to enter the specific process in
waiting state.
Syntax : wait pid
The wait command make process wait until all other
processes are terminated.
Sleep:
Suspend the execution of process for an interval of
time. Means, it is used to execute a command after
certain amount of time.
Syntax : sleep n
Where n is seconds.
Mounting & un mounting
(de- mounting)
Mounting :
All files in unix are arranged in file hierarchy with root as main directory. The
mount command serves the file system found on some other device to this file
hierarchy.
Stand form of mount is :
Mount –t type device dir
It tells the kernal to attach the file system found on device at directory dir. The
previous contents & owner mode of this directory become invisible.
Un mounting:
The un mount command detaches the file system mentioned from file
hierarchy. A file system is specified by giving directory where it has been
mounted.
File system can not be un mounted when it is busy. Files are opened or some
processes are executing that directory.
-f : force unmount
-n : if un mounting fails, try to remount.
Assignment -2
Q.no Questions marks
1 Write a short note on kernel & shell 3
2 List out and explain features of unix 5
3 Explain file structure of unix 3
4 Explain login commands 3
5 List out and explain file & directory commands. 3
6 Write a short note on vi editor 3
7 Explain different modes of vi editor 5
8 List out the cursor movement commands 1
9 List out and explain screen control commands 1
10 Explain redirection & piping. 5
11 Explain file finding patterns (grep,fgrep,egrep) 5
12 Explain cut & paste command 3
13 Explain join command 3
14 Explain tee command. 3
15 Explain script command. 3
16 Explain date & time commands 3
17 Explain communication commands 3
18 Explain process related commands 1
19 What is mounting & unmounting? 1