_UNIX_LAB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

UNIX FILE

Introduction to unix –

➢UNIX is an operating system that is a software that acts as an interface


between the user and computer h/w.

➢ An operating system acts as a resource manager.

➢ 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.

3. The file system: USING UNIX


 The process of getting into unix environment is known as ‘logging in’
into system.

 The sequence of events in a complete log in process is as follows:


 The user enters a login name of the getty’s login prompt on the terminal.
 Gety executes the login program with the login name as the argument.
 Login requests for a password and validates it against/etc/passwd.
 Login sets up the TERM environment startup file like profile.
 The shell then prints a prompts, usually a $ and a % symbol and waits for
future input. This indicates the successful entry made into a unix
environment with a paper shell.

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.

The shell prompt:


 Successful login into a unix system is indicated by the appearance of a
prompt called the shell prompt or system prompt on the terminal.
• The character that appears as a prompt depends on the shell used.
• $(dollar)-> bourne and korn shells(sh,bash,ksh)
• %(percent)-> C shell (sh and tesh)
• #(hash)->any shell as root.

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.

2. Internal commands: A command that does not have an independent


existence is called an internal command.
Ex. Echo,mkdir,cd,etc;
The routines for internal commands will be a part of another program (or)
routine.
Ex. Echo command is internal command will be a part of another program(or)
routine is the part of shell’s routine “sh”.

Some commands are there:


1.Execute the following list of basic commands in UNIX:

pwd :

Displays the path name of the working directory.

Syntax : pwd

Example

Note: pwd command does not working properly.

mkdir:
Creates one or more new directories.

Syntax : mkdir FileName


Example -

cd: Changes the current directory.


Syntax :

cd DirectoryName :

Example -

2.Execute the following list of basic commands in UNIX:

who : Identifies the users currently logged in.

Syntax
who [ -a | -b -d -i -l -m -p -q -r -s -t -u -w -A -H -T -X ] [ File ]
who am { i | I }

echo : Permits the user to write character strings to standard output.

Syntax :

echo <Content>
Example -

Cat : Concatenates or displays files.


Syntax :

cat > FileName.extension

If we want to display contents of the file .

Syntax :

cat FileName.extension

If we want to display reverse of the file.(staring lines are display as end lines)

Syntax : tac Filename.extension

rm:
Removes (unlinks) files or directories.
Syntax :

rm FileName.extension

Example -

mv: Moves files.


Syntax :

mv filename.extension [directoryname]

Example -

wc: Counts the number of lines, words, bytes, or characters in a file.


Syntax :

wc Filename.extensionwc

Example -
cp: Copies files.
Syntax : cp FirstFile.extension SecondFile.extension

Example -

ls: Displays the contents of a directory.


Syntax :

Ls -i

Example -

chmod: chmod changes the access permissions, or modes, of the specified file or
directory.
Syntax :

chmod [permission] FileName.extension

Example -

history: Displays the history of commands .


Syntax :

History

Example -

date: Displays or sets the date or time.


Syntax :

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.

Moving one word

w, to move the cursor right to one word

b, to move the cursor left one word

W & B to move the cursor past the adjacent to next or previous


blank space e to move the cursor to last character of current word.

Deleting :

X – Deleting single character under cursor

dw – Deleting single word beginning with character under cursor

Character text –
r – for replacing single character under cursor

c – change the character in the current line

Cut/copy/paste

yy – for copy

p – for paste

Matching pattern :-

Grep : Searches for a pattern in a file.


Syntax :

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:

Sed : A stream editor.


Syntax :

sed ‘s/oldpattern/newpattern/’ FileName.extension

Example -
 Shell script for date and time with calender.

cat

• Shell script program(taking file from student,starting and ending


line no. and display all the lines)

Output:
Filename
three.txt
Starting line
3
Ending line
4
sdhdff
fifofg

You might also like