You are on page 1of 15

Title:- Introduction of unix and study of unix commands.

Problem Statement:- To study the history, architecture, commands and


features of UNIX operating system.

History of Unix :

The Unix operating system found its beginnings in MULTICS, which stands for
Multiplexed Operating and Computing System. The MULTICS project began in the mid
1960s as a joint effort by General Electric, Massachusetts Institute for Technology and
Bell Laboratories. In 1969 Bell Laboratories pulled out of the project.

One of Bell Laboratories people involved in the project was Ken Thompson. He liked the
potential MULTICS had, but felt it was too complex and that the same thing could be
done in simpler way. In 1969 he wrote the first version of Unix, called UNICS. UNICS
stood for Uniplexed Operating and Computing System. Although the operating system
has changed, the name stuck and was eventually shortened to Unix.

Ken Thompson teamed up with Dennis Ritchie, who wrote the first C compiler. In 1973
they rewrote the Unix kernel in C. The following year a version of Unix known as the
Fifth Edition was first licensed to universities. The Seventh Edition, released in 1978,
served as a dividing point for two divergent lines of Unix development. These two
branches are known as SVR4 (System V) and BSD.

Ken Thompson spent a year's sabbatical with the University of California at Berkeley.
While there he and two graduate students, Bill Joy and Chuck Haley, wrote the first
Berkely version of Unix, which was distributed to students. This resulted in the source
code being worked on and developed by many different people. The Berkeley version of
Unix is known as BSD, Berkeley Software Distribution. From BSD came the vi editor, C
shell, virtual memory, Send mail, and support for TCP/IP.
For several years SVR4 was the more conservative, commercial, and well supported.
Today SVR4 and BSD look very much alike. Probably the biggest cosmetic difference
between them is the way the ps command functions.

 Different Unix systems :

UNIX has a rich variety of editors available ranging from the minimal to the truly exotic.

The vi Editor

In 1976, Bill Joy took the sources of the two line editors ed and ex, and created vi. Vi
soon attracted a large following and has since evolved into many different versions for
many platforms. Vi is the default Unix editor.

1. The Pico Editor

Pico is an extremely simple and easy to use editor. It was written in 1989 for the email
client Pine by the administrative staff of the University of Washington.

The Emacs Editor

The first Emacs was born in 1975 at MIT as a set of macros written for the editor TECO
under ITS on a PDP-10 machine. It was written by Richard Matthew Stallman (RMS).
RMS went on to write the now widely popular GNU Emacs as part of the GNU project.
 Architecture of Unix Operating System :

• Hardware :

This contains all the various hardware devices connected to the system.

• Kernel :
o The core of the UNIX system. Loaded at system start up (boot). Memory-
resident control program.
o Manages the entire resources of the system, presenting them to you and
every other user as a coherent system. Provides service to user
applications such as device management, process scheduling, etc.
o Example functions performed by the kernel are:
 managing the machine's memory and allocating it to each process.
 scheduling the work done by the CPU so that the work of each user
is carried out as efficiently as is possible.
 accomplishing the transfer of data from one part of the machine to
another
 interpreting and executing instructions from the shell
 enforcing file access permissions
o You do not need to know anything about the kernel in order to use a
UNIX system. These details are provided for your information only.
• Shell :
o Whenever you login to a Unix system you are placed in a shell program.
The shell's prompt is usually visible at the cursor's position on your screen.
To get your work done, you enter commands at this prompt.
o The shell is a command interpreter; it takes each command and passes it to
the operating system kernel to be acted upon. It then displays the results of
this operation on your screen.
o Several shells are usually available on any UNIX system, each with its
own strengths and weaknesses.
o Different users may use different shells. Initially, your system
administrator will supply a default shell, which can be overridden or
changed. The most commonly available shells are:
 Bourne shell (sh)
 C shell (csh)
 Korn shell (ksh)
 TC Shell (tcsh)
 Bourne Again Shell (bash)
o Each shell also includes its own programming language. Command files,
called "shell scripts" are used to accomplish a series of tasks.
• Utilities :
o UNIX provides several hundred utility programs, often referred to as
commands.
o Accomplish universal functions
 editing
 file maintenance
 printing
 sorting
 programming support
 online info
o Modular: single functions can be grouped to perform more complex tasks .
 UNIX File System and Commands

The standard system directories are shown below. Each one contains specific types of
file. The details may vary between different UNIX systems, but these directories should
be common to all. Select one for more information on it

/(root)
|
--------------------------------------------------------------
| | | | | | | |
/bin /dev /etc /home /lib /tmp /usr kernel file

Absolute pathnames:

Every file and directory in the file system can be identified by a complete list of the
names of the directories that are on the route from the root directory to that file or
directory.

Each directory name on the route is separated by a / (forward slash). For example:

/usr/local/bin/ue

This gives the full pathname.


Relative pathnames:

You can define a file or directory by its location in relation to your current directory. The
pathname is given as / (slash) separated list of the directories on the route to the file (or
directory) from your current directory.

A .. (dot dot) is used to represent the directory immediately above the current directory.

 Unix Commands :

• Directory related commands :

A) Create and Remove Directories:

1. mkdir - to create a new directory.


mkdir <name>

2. rmdir - to delete a directory.


-r to delete all files and subdirectories before deleting directory.
rmdir[-r]<name>
B) Navigation:

1. cd - to change directory.
cd<name>

2. ls - to list all files in directory ( by default, all files in the working


directory).
-a displays all files and subdirectories including hidden files.
-l displays detailed information about each file and directory.
-p displays a / at the end of each directory to distinguish then from
filenames.
-r displays files in reverse order.
-R includes contents of the subdirectories.
-t displays files in order of modification time.
-x displays filenames in several columns across the screen.
Pathnames file(s) or directory(s) to list.
ls [-a][-l][-p][-r][-R][-t][-x][<pathname>].

3. pwd - to display name of current working directory.


pwd
4. rm - to delete a file permanently ( However, if link to file is present then
file isn’t deleted instead the file cannot be addressed by the name
specified.
-i ask for confirmation.
-r delete entire directory and all files it contains.
rm[-i][-r] <filename>

5. mv - to rename a file or to move it from one directory to another


-i tell mv to ask before overwriting an existing file by renamed file.
mv[-i] <oldname> <newname> or
mv[-i] <filename> <directory> [/<newname>]

• FILE RELATED COMMANDS:


A) Searching:
1. grep - to find lines in one or more files that contain a particular word or
phrase.
-i ignore spaces.
-l displays only those files containing the actual text.
-v specifies that you are looking for lines that don’t contain the text.
grep[-i][-l][-v] <text> <filenames>

B) Display:
1. cat - to display a file on the screen.
cat <filename>
2. head - to display first few lines (usually 10) of a file.
-lines specifies the number of lines to display.
head<[-lines] <filename>

3. tail - to display a last few lines of a file.


-r displays the lines in the reverse order.
-lines specifies the number of lines to display.
tail [-r][-lines] <filename>

4. more - to display the information a screen at a time.


-l ignores form feed characters in the file.
-r displays control characters.
-s removes extra blank lines.
-u ignores underscore and backspace.
more [-l][-s][-r][-u][filename]

C) Editing :

1. chmode - to change the permissions for a file


-R to change the permissions in files in subdirectories, too.

Code Who gets permission


User that owns the file
G Group that owns the file
O Everyone else
Code What kind
A everybody r Read the file
w Write/edit file
x Run file as prog.

chmode [-R] <permissions> <filenames>


2. cp - to copy or more files.
-i ask before replacing existing file with copied file.
-r copy subdirectories as well.
cp [-i] <oldfile> <newfile> or
cp[-i][-r] <oldfile> <directory> [/<newfile>]

3. cmp - to compare two files and tell the line numbers where they differ.
cmp <onefile> <anotherfile>

• Process control commands :


1. ps - lists the current running processes.

Example:

PID TTY TIME CMD


6874 pts/9 0:00 ksh
6877 pts/9 0:01 csh
418 pts/9 0:00 csh

2. kill- Cancels a job.

kill [-s] [-l] %pid

example – kill -s kill 100 -165 ----- Kills job 1 of uid 165

3. shutdown - Turn off the computer immediately or at a specified time.

example: shutdown 8:00 Shutdown the computer at 8-oclock

• Office Automation Commands :


1. passwd – used to change the password.
example: for a user whose login name is "user11”
% passwd (User command)
Changing password for user11 (System response)
Old password: (System prompt and non-displaying user esponse)
New password: (System prompt and non-displaying user response)
Retype new password: (System prompt and non-displaying user
response)
% (System prompt)

2 cal - Calendar for the month and the year.

cal [month] [year]

example - cal - Would give you the calendar for this month.
cal 12 2000 - Would give you the calendar for December of 2000.

3 date - write the date and time

date -s "11/20/2003 12:48:00" - Set the date to the date and time shown.

date '+DATE: %m/%d/%y%nTIME:%H:%M:%S' - Would list the time and date


in the below format:

DATE:02/08/01
TIME:16:44:55

4 mount - used to mount floppy/cd-roms/filesystems

When using mounting, the mount command must know what is the device or partition to
be mounted and what is the mount point. The mount point must be a already existing
directory on the system.
Example: $ mount /dev/fd0 /mnt/floppy
Here /dev/fd0 is floppy drive and /mnt/floppy is the mount point..

5 umount – unmounts the mounted floppy/cd-


roms/filesystems
When unmounting, the umount command must know the device to unmount either by the
device name or by the mount point.
Example: $ umount /mnt/floppy
here /mnt/floppy is the mount point

or $ umount /dev/fd0
here /dev/fd0 is the device to umount

6 fsck-file system check


Used to check the file system and repair damaged files. The
command takes a device name as an argument
example: $ /etc/fsck /dev/file-system-to-be-checked.
• Redirection of Input and Output :
1. Redirected Output
This is done by typing
command > outputfile

Example:
The command will print details of your files on the screen.
$ ls -l > bigfile
Will create bigfile which contains output of ls –l command.

2. Appended Redirected Output


Very similar to the above, but it is entered like this.
command >> outputfile

Example
$ cat file3 >> bigfile
Will add the contents of file3 to the end of bigfile. The old contents of bigfile are not
deleted by this.

3. Redirected Input
Redirected input is run by typing a command like this
command < inputfile
The program reads its input data from the file instead of the keyboard.

 Features of Unix :
• It is multitasking, therefore, multiple programs can run at
one time.
• It is multiuser, allowing more than a single user to work at
any given time. This is accomplished by sharing processing
time between each user and utilizing distributed computing
systems.
• It is safe, preventing one program from accessing memory
or storage space allocated to another, and enables
protection, requiring users to have permission to perform
certain functions, i.e. accessing a directory, file, or disk
drive.

 Vi Editor :

What is vi?
The fundamental UNIX editor is called vi. It is a primitive editor, but it will be found on
every UNIX system, and works well when logging in remotely from home. There are just
a few commands that one needs to learn at first, and they will be sufficient to write
simple files. For more advanced features, consult some of the handouts and books
available in the CS lab.

The Basics of vi :
There are essentially three Modes in vi, the Insert Mode where one is typing in new text,
the Edit Mode where one is modifying text that is already there, and the Command
Mode where one is interacting with the operating system with actions like reading and
writing files.

Most of the commands require just a simple letter or two, but be careful to note that vi is
case sensitive, and capital letters do different things from lower case letters. It is not
necessary to learn all of these commands, but eventually they will become second nature.
The basic operations needed to create a file are related to each of those modes, so let's
look at them separately.

• INSERT Mode : For adding text to a file


The three most common ways to enter the Insert Mode are:

Letter Action

i Starts inserting in front of the current cursor position

I Starts adding at the front of the line

a Starts adding after the cursor

A Starts adding at the end of the line

o Starts opening a new line underneath the cursor

O Starts opening a line above the cursor.

<Esc> Gets out of Insert Mode


• EDIT Mode - Generally for moving the cursor and deleting stuff.
In the Edit Mode, the keys do not type letters, but do other actions such as cursor
movement, deletions, copying lines, etc.

Letter Simple Cursor Movement

h Moves cursor left one space


Note: the Arrow keys do
j Moves cursor down one line work locally, but

k Moves cursor up one line sometimes mess up over


a network.
l Moves cursor right one space

Fast Cursor Movement

w Moves the cursor a full word at a time to the right

b Moves the cursor back to the left a word at a time

^ Moves the cursor to the front of a line

$ Moves the cursor to the end of a line

<ctrl>f Moves the cursor forward a full page of text at a time

<ctrl>b Moves the cursor backward a full page of text at a time

Modifying Text

x Deletes the character under the cursor

dd Deletes the line where the cursor is located (type d twice!)

n dd Delete n consecutive lines ( n is an integer)

Replaces the character under the cursor with the next thing
r
typed
J Joins current line with the one below (Capital J!)

u Undoes the last edit operation

<ctrl> r Redo (Undoes the last undo operation)

Cut and Paste Operations

yy Copies or yanks a line ( 5yy yanks 5 lines)

p Puts the yanked text on the line below the cursor (lower case p)

P Puts the yanked text above the current line (capital P)

Note: If vi is already in the input mode, text from that or another window may be
highlited using the left mouse button, and copied into place by pressing the
middle mouse button.
• COMMAND Mode - For interacting with the operating system.
To enter the Command Mode, a colon " : " must precede the actual command.

Letter Action

: r <file> reads a file from disk into the vi editor

: w <file> writes current file to disk

: wq writes the file and quits vi

: q! quits without writing (useful if you've messed up!)

You might also like