_UNIX_LAB
_UNIX_LAB
_UNIX_LAB
Introduction to unix –
➢ Here resources mean hardware resources like the processor, the main
memory, the hard disk, i/o devices and other peripherals.
➢ In addition to being a multi-user operating system UNIX gives its users, the
feeling of working an independent computer system.
UNIX also provides communication facility with other users who are connected
to the system either directly or indirectly via certain sort of networking.
UNIX is an Operating System that is truly the base of all Operating Systems
like Ubuntu, Solaris, POSIX, etc. It was developed in the 1970s by Ken
Thompson, Dennis Ritchie, and others in the AT&T Laboratories. It was
originally meant for programmers developing software rather than non-
programmers.
UNIX components
Unix contains 3 major components.
1. The kernel
2. The shell
3. The file system
In addition to these components all unix systems also contains genral utility
programs.
1. The kernel:
➢ The kernel is the heart of any UNIX OS.
➢ This kernel is relatively a small piece of code written in ‘c’ that is embedded
➢ Every Unix system has a kernel that gets automatically loaded on to the
memory as soon as system is boosted.
➢ The kernel is the only component that can communicate with all hardware
directly.
➢ Kernel manages all the system resources like memory and i/o devices on the
hardware, allocated time between users and processes in the case of multi-user
environment, decides process priorities, manages inter process communication
and performs many other such tasks.
Monolithic kernels:
Earlier, all the programs that were part of a kernel , were integrated, together
and moved onto the memory during booting. Such integrated kernels are
referred to as,’ monolithic kernels’.
Micro kernel: Now -a-days, all the programs are grouped into different
modules and only the just necessary module is moved on to the memory during
boating. This just necessary and sufficient module consisting of a small set of
kernel program is called a “micro kernel”
2. Shell:
Every UNIX system has atleast one shell. A shell is a program
that sites on kernel and acts as an agent or interface between the users and the
kernel and hence the hardware. A shell is a command interpreter or processor at
which the user can type in any UNIX command.
Types of shells: There are different types of shells available. Some of them are.
✓ The bourne shell (sh):
This is the first major shell to be developed and is named after its author,
Stephen bourne.
This is the most common shell and is distributed as the standard shell on almost
all unix systems.
✓ C shell(csh):
Bill joy , developed this shell at VCB as a part of the BSD release .
• It is called c shell because is syntax and usuage is very similar to the ‘c’
programming language .
✓ Korn shell(ksh):
This shell was developed by david korn at AT &T bell labs.
• It has the both features of bourne shell and c shell and is one of the widely
used shells.
✓ Bourne-again shell (bash):
➢ A file system is another major component of a Unix system.
➢ Unix treats everything including hardware devices as a file.
When the user completes the session with system the comes out of unix
environment .The process of coming out of unix environment is known as
logging out.
Architecture of unix
catcleraclear
Layer-1: Hardware –
It consists of all hardware related information.
Layer-2: Kernel –
It interacts with hardware and most of the tasks like memory
management, task scheduling, and management are done by the kernel.
Layer-3: Shell commands –
Shell is the utility that processes your requests. When you type in a
command at the terminal, the shell interprets the command and calls the
program that you want.
There are various commands like cp, mv, cat, grep, id, wc, nroff, a.out
and more.
Layer-4: Application Layer –
It is the outermost layer that executes the given external applications.
Commands in UNIX:
Unix has large number of commands. Types of Unix commands:
➢ There are 2 types of Unix commands. They are
1. External commands
2. Internal commands
1. External commands: A command with an independent existence in the form
of a separate file is called an external command.
Ex: cat and ls . these are independently existed in a directory called the / bin
directory .
When external commands and given the shell reaches these command files with
the help of ‘PATH’ variable.
pwd :
Syntax : pwd
Example
mkdir:
Creates one or more new directories.
cd DirectoryName :
Example -
Syntax
who [ -a | -b -d -i -l -m -p -q -r -s -t -u -w -A -H -T -X ] [ File ]
who am { i | I }
Syntax :
echo <Content>
Example -
Syntax :
cat FileName.extension
If we want to display reverse of the file.(staring lines are display as end lines)
rm:
Removes (unlinks) files or directories.
Syntax :
rm FileName.extension
Example -
mv filename.extension [directoryname]
Example -
wc Filename.extensionwc
Example -
cp: Copies files.
Syntax : cp FirstFile.extension SecondFile.extension
Example -
Ls -i
Example -
chmod: chmod changes the access permissions, or modes, of the specified file or
directory.
Syntax :
Example -
History
Example -
date
type: type is a command that describes how its arguments would be
interpreted if used as command names.
Syntax :
type command
Example -
Vi editor:
The default editor that comes with the UNIX operating
system is called vi (visual editor). Using vi editor, we can edit
an existing file or create a new file from scratch. we can also
use this editor to just read a text file.
Syntax :
vi Filename.extension
Creation:
Texting in file:
i : Inserts text before cursor
I : Inserts text at beginning of current line
Quit:
Esc+:q = for quit
Esc+:q! = for quit
Esc+wq =for write and quit
Navigation
To move left, press h
To move right, print l
To move down, press J
To move up, press k.
Deleting :
Character text –
r – for replacing single character under cursor
Cut/copy/paste
yy – for copy
p – for paste
Matching pattern :-
grep [ -E | -F ] [ -i ] [ -h ] [ -H ] [ -L ] [ -r | -R ] [ -s ][ -u ] [ -v ] [ -w ] [ -x ] [ -y ] [ [ [ -b ]
[ -n ] ] | [ -c | -l | -q ] ] [ -p [ Separator ] ] { [ -e PatternList ... ] [ -f PatternFile ... ]
| PatternList ... } [ File ... ]
Word matching using grep command:
Example -
Shell script for date and time with calender.
cat
Output:
Filename
three.txt
Starting line
3
Ending line
4
sdhdff
fifofg