Unix
Unix
Unix
It is a popular multi user time sharing operating system intended for document
preparation and program development tasks. It is written in high-level languages, ‘C’
with careful isolation and confinement of machine dependent features. Some of the
salient features of UNIX:
Portability: It is available and portable on a wide range of different hardware. It is
written with hardware-dependent code into a few modules only.
Multi user Operation: It provides more than one users on suitable installations
with proper communication interface and memory management hardware. In
addition to local users, remote users can also get hooked onto the system and
perform file transfer in network configuration.
Device independence: Files and devices such as disks, tapes are treated in a
uniform manner. I-O redirection is possible at both the command language and
system call levels.
Hierarchical File system: It’s hierarchical file system helps in organizing / storing
the information effectively. It offers maximum flexibility in grouping information
in way that reflects its natural structure.
Multitasking Operating system: This means that the system can perform several
tasks – called “processes” at the same time.
3. Unix System Architecture
The Unix System Architecture is shown in the Figure 1. The layers of architecture are
described:
Kernel is the part of the system which manages the resources of whatever
computer system it stays on, to keep track of printers, disks, tapes, etc.,
File System is responsible for organizing the data. It not only acts as a
repository for data but provides the means of organizing the layout of the data
storage in complex ways.
Shell is a command interpreter. It is a utility program. Programs such as shell
and editors shown in the outer layers communicate with the underlying kernel
by invoking a well-defined set of “system calls”.
Applications programs like the standard C compiler, cc, and exist on the
outermost layer. It invokes a c preprocessor (cpp), assemblers (as), etc.,
There are two types of users. Super user is known an system administrator. He is
responsible for creating, allowing, modifying, or deleting / disallowing the access
to the UNIX system by other users. Ordinary users can access the files.
Minimum requirements of Unix System:
8 MB of RAM space
10 MB Hard Disk
16-bit CPU
Identify the UNIX version in your lab and the system configuration.
Exercise 2 : Getting Started
Login process
Login:
Password:
The password typed by user will not appear on the screen. Finish the entry of
b) Prompt
$ Bourne Shell
% C Shell
The appearance of prompt on the screen indicates that UNIX has finished execution
Logging OFF
After finishing the work with the system, sign-off simply by typing Ctrl and D keys
together. This should log out the screen and displays the login: prompt again.
Exercise 3: Simple Commands in UNIX
Date command tells the system to print the date and time.
$ date
Output:
who command tells about all the users who is currently logged-in into the unix
server. The output contains userid, name of the terminal, month date time.
$ who
Output:
who am I command tells about the user currently logged into that particular
system.
$ who am i
Output:
Password command is used to change the password of the user. The new
password should be typed twice.
$ password
Output:
Exercise 4: Files and Directory
Unix files and directories can be organized by the users. The guidelines for naming
are:
Can be one to fourteen characters long
root
<studentuserid>
The student userid is a home directory for the user and it is login name. UNIX system
always associate each user of the system with a particular directory. When logged-into
the system, the user is automatically placed into a directory called HOME directory.
A path name enables to uniquely identify a particular file to the UNIX system.
Absolute path name contains complete road may of directory or file from root
directory onwards. Example
/usr/studentuserid
Relative path name are relative to the directory the user is in. Example:
./studentuserid
To print the current working directory
$ pwd
Output:
$ mkdir BMI
$ cd BMI
$__________
ls command is used to list the contents of the directory.
$ ls
Output:
$ ls –a
Output:
$ ls – l
Output:
The listing includes file mode, number of links, owner name, group name, file
size in bytes, date and time of last modification, and file name or directory name.
$ ls –ld BMI
Output:
$ cp file1 file2
moving and rename the file file2 as file3
$ mv file2 file3
$ rm file3
$ rmdir bmi
For every file and every directory in the file system, there are 3 classes of users who
may have access. Those ownerships are:
r w x r w x r w x
$ Chmod go – rx file1
who is Action permission file
affected affected affected
Another example:
The screen editor used in Unix system V is vi. vi stands for “visual”. The vi can
be invoked by using the command:
$ vi filename
ZZ Press upper case Z twice to save the content and system takes the user to
command line.
:wq Press the keys :wq in the same sequence, the contents are written onto the
disk and quit operation is executed thereby taking to the system prompt.
:q! Press the keys :q! in the same sequence, the contents are not written to the
disk. The system would then display the prompt
Cursor movements
H moves cursor to the first character on the first line on the screen
M moves cursor to the first character on the middle line on the screen
L moves cursor to the first character on the last line on the screen
Scrolling
Uppercase U command undo the various changes at the same time, but only those
made on the same line.
The x command is used to delete the character on which the cursor is placed. To
gobble 5 characters type x five times or 5x.
To replace the character, type r followed by the character at that position. It keeps
on replacing until the <esc> key is pressed.
To delete the particular line type dd. To delete two lines type 2dd.
Create the file “file2” to store the details of country and capital
$ sort file2
output:
$ sort+1 file2
output:
$ sort-b+1 file2
output
The wc command counts the number of characters, words, and lines in a file.
$ wc file2
output:
output:
output:
output:
To show the line numbers of lines that match the string or pattern
output:
Exercise 7: Shell Features
Unix derives its power and flexibility largely out of the user interface that is
built into the system. The user interface within the UNIX is established by a
sophisticated utility program called sh (shell). It is a command interpreter. It
accepts commands from the user, interprets them and calls upon the kernel to
actually perform the operations required. The flavors of shell are Bourne
shell, C shell, Korn shell, and visual shell.
$ ls file?
$ ls f*
$ ls file[1-5]
Input redirection is used to display the content of the file to the standard
output file e.g. monitor.
$ who | wc –l
output:
Filters
A command which accepts its input from the standard input and produces the
output on the standard output, is known as filter.
Grouped commands
Simple commands can be grouped by using ;
$ cat xyz; ls
o MAIL
This variable’s value is name of the directory to which your mail is
sent via the mail command. Shell checks contents of this directory
whenever login. When something is mailed, you are intimated that the
mail has arrived for you.
o PATH
This names the directories which are searched by shell commands.
A colon is used to separate the directory names; there are no spaces.
path=.:/bin:/usr/bin
o PS1 (Prompt string 1) Normally $. It can be redefined./
o PS2
This prompt is used when UNIX thinks you have started a new line
without finishing a command. > You can continue the line by typing
backslash(\) before hitting a return key.
o TERM
This is used to identify the kind of terminal you would usually use.
Example:
$set
HOME=/usr/student1
IFS=
MAIL=/usr/mail/student1
PATH:/bin:/usr/bin
PS1=$
PS2=>
TERM=ansi
$
Setting shell variables
To create shell variable type name and assign value
Age=25
Fruit=apple
There should not be any blank spaces surrounding the = sign.
When you login a sub-shell gets created for you. Some variables like PS1 and
PATH are given to it. Then shell will look for a .profile file and follows the
instructions it finds in .profile. System administrator would normally, give a
copy of this file in home directory. A typical .profile file contents are
reproduced below:
$ cat.profile
export MAIL PATH TERM
umask 22
TERM=ansi
$
Example
$ cat > greet
echo “ may I know your name\?\n”
read name
echo “god bless you, $name\n”
$
The arguments are referred by $1 and $2 respectively. $0 is reserved for the name
of the shell script itself.
It will throw away already assigned value of $1 and assigns the value of $1 to $2.
Then it sets the value of $2 to old value of $3 and so on.
example:
for month in 1 2 3 4 5
do
cal $month 2007
done
case construct example
case $1 in
0) echo zero::
1) echo one::
*) echo “ I cant understand”
esac
while loop example
c=1
while test $c –le 10
do
echo $c
c=’expr $c+1’
done
i-nodes: contain more blocks- depends on file systems. – one i-node for every fileand
directory. – description of file, permissions and links
unmount file
#/etc/unmount devicename
$ ls –l /dev: list Devices special files
The presence of character c indicates character oriented device
B indicates block oriented device
During bootstrap
Kernel invoke init program, getty program display login prompt, login program
validate user. Getty would take place with login prompt.
Process management
Fork : create child process
Ps to view process id and parent process id
Kill to destroy the process
Communication
Cu: call unix : allow a user connected as one Unix system to login temporarily to
another system, provided he/she has a valid user account in remote unix system
also.