Top Banner
CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written in assembly language Developed as multi-user OS later Rewritten in C in 1973 Licensed to university for educational purposes in 1974
59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

Mar 26, 2015

Download

Documents

John Gray
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1

History of Unix

Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969

Initially written in assembly language

Developed as multi-user OS later

Rewritten in C in 1973

Licensed to university for educational purposes in 1974

Page 2: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 2

Unix Flavors AIX by IBM

Solaris by Sun Microsystems

HP-UX by Hewlett-Packard Company

IRIX by Silicon Graphics, Inc.

BSD by University of California

GNU/Linux by Open Source Movement

MacOS by Apple Computer, Inc.

System V by AT&T

POSIX by IEEE

Page 3: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 3

Features of Unix

Multi-user

Multi-tasking

Portable

Interactive

Hierarchical File System

Page 4: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 4

Unix Architecture

Hardware Kernel

Shell & Unix Utilities

Other Application Program

Page 5: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 5

Directory Structure

cat

ls

user2 user3user1

progrm1

progrm2

bin boot home etc usr dev lib

Desktop

start

/

Directory

File

Page 6: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 6

File Basics

Everything on Unix is a file. File structure is hierarchical like an upside down tree.

File is just a sequence of bytes.

The meaning of the bytes depends solely on the programs that interpret the file.

The format of a file is determined by the programs that use it.

Page 7: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 7

File Attributes

Name (such as “test.log”)

An Owner (such as “sandhya”)

Access Rights (such as read, write, execute)

Other attributes (such as date of creation)

Among these attributes, file names are stored in the directory but other attributes like file-size, permission, links, time-stamps are stored in the inode.

Page 8: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 8

File Types

Every item in a UNIX file system belongs to one of the four possible types:

1. Ordinary/Regular files

2. Directory files

3. Device/Special files

4. Symbolic links

Page 9: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 9

Ordinary File

Contains text, data, or program information

Cannot contain another file or directory

Can be thought of as one-dimensional array of bytes

Page 10: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 10

Directory File

Contains directory(s) and/or file(s) within it.

Has one line for each item contained within the directory.

Each line in a directory file contains only the name of the item, and a numerical reference to the location of the item, called inode number.

Inode number is an index to a table known as the inode table. Inode stores all information about the file except its name.

Page 11: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 11

Device File

Physical devices (printers, terminals etc) are represented as “files”.

The read() and write() functions used to read and write ordinary files can also be used to read from and write to these devices.

Two types of device files:1. Character Special2. Block Special

Page 12: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 12

Symbolic Link

Links make the same file available in multiple directories at the same time Two types of Links:

1. Hard Link2. Soft Link or Symbolic Link

1. Hard Link A hard link is another name given to the existing file These names share the same inode UNIX command ln is used to create hard links:

ln file1 file2

2. Soft Link A soft link to a file has a separate inode than the file It stores the target file’s path in its inode UNIX command ln –s is used to create soft links:

ln –s file1 file3

Page 13: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 13

Inode

Inode is a data structure containing useful information about an item in the Unix File System.

Inodes reside on disk and do not have names. Instead, they have indices (numbers) indicating their positions in the array of inodes as shown in the next slide.

Page 14: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 14

Inode

Page 15: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 15

Pathname

Every item in the file system with a name can be specified with a pathname.

Pathname represents the path to the entry from the root of the file system. By following this path, the system can find the inode of the referenced entry.

Pathnames can be absolute or relative.

Page 16: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 16

Unix Users

Super User

Owner

Group

Others

Page 17: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 17

Unix Users

Superuser Can also be referred to as a System Administrator Has an overall authority on Unix OS Responsible for OS maintenance, backup and recovery, user

management etc. Superuser login is root and prompt is #

Owner Is a user who creates a file For every Unix file there can be only one owner File owner can assign the file permissions to group and other

users

Page 18: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 18

Unix Users

Group In Unix, groups can be formed based on area of work Superuser can create a group and assign members to it Owner of a file can decide what permissions to be given to

group members

Others User who is not a owner and does not belong to any specific

group is referred to as other user Owner of a file can decide what permissions to be given to

other users

Page 19: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 19

Unix Commands

Page 20: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 20

Basic Commands

$ pwdShows working i.e current directory

$ whoShows who is logged on

$ who am IShows the login name of the current user

Page 21: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 21

Basic Commands

$ man command formats and displays online manual pages

The manual pages are divided into logical grouping of the commands called the sections. Sections are numbered from 1 through 9. For example, commands are 1, system calls are 2, library function are 3, file formats are 5, & management commands are 8.

If section is specified, man only looks in that section of the manual.

The command man 2 open displays the manual for the system call open.

Page 22: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 22

Basic Commands

$ date: command prints or sets the system date and time

For example,$ date$ date –r TestFileDisplays the last modification time of the file “TestFile”

This command can be used with suitable format specifiers as argument. Each format is preceded by a + symbol, followed by the % operator, and a single character describing the format.

Page 23: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 23

Basic Commands

Sequence Interpretation

%a abbreviated weekday name (Mon .. Sun)

%b or %h abbreviated month name (Jan .. Dec)

%d day of month (01 .. 31) %r time (12- hour) %T time (24- hour) %y last two digits of year (00 .. 99) %D date (mm/dd/yy)

e. g. $ date “+Today is %a %m %Y”

Page 24: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 24

Basic Commands

echo “Hi $USER \n Welcome to Unix”

echo ‘Hi $USER \n Welcome to Unix’

echo Hi $USER \n Welcome to Unix

clear

Page 25: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 25

Basic Commands

$ cal Shows the calendar of the current month/year

$ bc 2.3+5.4

Shows the mathematical calculations involving integers as well as floats

bc is a filter command

$ write user1 Lets to write a message to the other user; user1 in this

example

Page 26: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 26

File Management Commands

$ ls command to list files and directories

Option Description-l list in long format

-C multicolumn output -F indicates type of file by /, * -R recursive listing of all subdirectories

encountered -a list all files including hidden files -i List all files along with i-node number

Page 27: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 27

Wild Card Characters

* - zero or more characters - ex ls m* lists all the files starting with m

? – single Character -ex ls m? lists all the files starting with m and having one character after that

[]- any character from all the characters within [] ex ls [aeiou]* lists all the files starting with a or e or i or o or u

- Specifies range

! – works as not operator ex: ls[!x-z]* will list all the files not starting with any character from the range x-z

Page 28: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 28

File Management Commands cat

To concatenate files To display contents of one or more ordinary files To create an ordinary file

$ cat file1 file2 … It displays contents of all files specified on the command line

one below the other

$ cat > file It creates a new file by accepting text from the standard input Press CTRL-d to save and exit the file

Page 29: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 29

File Management Commands

cd [directory] changes working directory to the directory, if specified;

otherwise to the home directory

cd .. moves to the parent directory and cd. keeps you in the current directory

Page 30: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 30

File Management Commands

cp command copies files and directories

$ cp –i file1 file2 Copies file1 to file2 -i - informs user before overwriting, if file2 exists

$ cp file1 file2 … dest_directory Copies multiple files in the specified existing directory

$ cp -r directory1 directory2 … dest_directory Recursively copies files from directory1, directory2 etc. to the

dest_directory

Page 31: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 31

File Management Commands

mv command changes name of the file or moves the file to the specified destination path

$ mv file1 new-file Renames file1 as new-file

$ mv file1 file2 … dest_directory Moves multiple files to the specified existing directory

$ mv directory1 directory2 … dest_directory Moves one or more directory subtrees to an existing or new

dest_directory

Page 32: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 32

File Management Commands

rm command is used for deleting unwanted files/directories

$ rm [-i] file … It is interactive removal (option –i) of specified files

$ rm -r directory … It is recursive deletion of all the files within the specified

directories and also the directories themselves

Page 33: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 33

Creating Links

ln file1 file2 Creates a hard link to existing file file1 with the name file2 in

the current directory Both names point to the same inode

ln –s file1 file3 file3 is a soft / symbolic link to file1 here Removal of file1 affects file3

Page 34: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 34

Finding Files and Directories

find command is used for finding files and directories in the specified file tree based upon certain criteria

Command Syntax:$ find path criteria actione.g.

$ find /usr -name “ymess*” –print

Finds files recursively in the directory in path The path can be absolute or relative Multiple directories can be written in the path In the criteria, wild cards are allowed

Page 35: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 35

Finding files by name:

find /home/user1 -name “*.sh” -print

finds all files with .sh extension in /home/user1 and its subdirectories

Finding files by type:

find /usr –type d –print

finds all directories in /usr and its subdirectories

find /var –type f –print

finds all regular files in /var and its subdirectories

Finding Files and Directories

Page 36: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 36

Finding Files and Directories

Find files and take some other action than printing

find . –name “*.sh” –exec cp {} {}.bak \;

Finds all files with the extension .sh, in the current directory and its subdirectories, and then prepares a copy of each file with .bak extension

Page 37: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 37

File Comparison

comm compares two sorted files and produces result in three colums:Lines: Unique to file1 Unique to file2 Common

$ comm file1 file2 Anil 12 2000

Ajit 12 2000 Dinesh 27 1400

Sunil 12 2000

Page 38: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 38

File Access Permissions

chmod command is used to change the permissions on a file for owner, group and otherschmod <permission><filename>

Symbolic Method: Code Meaning

a allu userg groupo other+ add- remove= assign

chmod u+x, g-w, o+r, o-wx sample

Page 39: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 39

File Access Permissions

Absolute value Method: Code Meaning 4 Read 2 Write 1 Execute

$ chmod 754 sample

Page 40: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 40

File Access Permissions

umask command changes initial permission of newly created file

The value of argument can be calculated by subtracting the mode you want as default from the current default mode

Assume that the current default mode is 0666 and you want it as 0644 then 666 – 644 = 022 will be the parameter which we have to pass with “umask” command

$umask 0 – sets default mode which is 0666

Page 41: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 41

Pipes

It is a feature by which filters & other commands can be combined in such a way that the standard output of one filter or command can be sent as standard input to another filter

e.g. $ ls >temp $ more temp

Ls |

moreInput Output

| $ ls | more

pipe

Page 42: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 42

Filters

wc: counts lines, words and characters $ wc -[wlc] [filename]

head: displays first ‘n’ lines, horizontal slicing $ head -[n] [filename]

tail: displays last ‘n’ lines, horizontal slicing$ tail -[n] [filename]

split: divides files horizontally$ split -[n] [filename]

We get m subfiles of size n (xaa, xab,…)

Page 43: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 43

Filters

cut: cuts file vertically either column wise/field wise

$ cut -[cfd] [filename] -c columns/characters -f field number -d field delimiter/separator

$ cut -c2-5 sample cuts columns 2 to 5 from the file sample

Page 44: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 44

vi Editor

Page 45: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 45

The vi editor

The vi editor is a screen-based editor which lets a user create new files or edit existing files

A key concept in vi is combining a certain action with a movement

vi is extremely powerful in moving around within (or between) files

Page 46: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 46

The vi editor

A vi session begins by invoking the command “vi” with a filename

$ vi [filename]

You can start vi without a filename, but when you want to save your work, you will have to tell vi which filename to save it into.

The last line in the screen is reserved for some commands that you can enter to act on the text. This line is also used by the system to display messages.

Page 47: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 47

Modes of Operation

The three different modes of operations are: Command mode: This is the default mode where you can pass

the commands to act on the text, using most of the keys of the keyboard

You can switch to this mode using “Esc” key

Insert (Input) mode: To enter the text, you have to enter into input mode. Press key “i” to enter into insert mode from command mode

You can switch to command mode by pressing “Esc” key

ex mode or line mode: You have to save your file or switch to another file or make a global substitution in the file. You then have to use ex mode, where you can enter the instruction in the last line of the screen. To enter into this mode, press “Esc” key followed by “:”

Page 48: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 48

Text Insertion Commands

Command Description

i inserts text before cursor position a Appends text after cursor position I inserts text at beginning of line A Appends text after end of line o opens line below current line to insert text O opens line above current line to insert text

Page 49: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 49

Cursor Movement Commands

Command Description

h left by one characterl right by one characterk up by one linej down by one linew right by one wordb left by one word0 or ^ beginning of line$ end of line

Page 50: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 50

Cursor Movement Commands

Command Description

ctrl+u move up half window

ctrl+b move up full windowctrl+d move down half

windowctrl+f move down full

windowctrl+e scroll downctrl+y scroll up

Page 51: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 51

Text Search Commands

Command Description

/text searches and highlights the text downwards n moves between highlighted text * searches the identical text on which the

cursor was ?text searches the text upwards

Page 52: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 52

Text Deletion Commands

Command Description

x character under cursorX character before cursor[n]dw delete n wordsd0 beginning to cursor positiond$ or D cursor position to end of line[n]dd n lines from current line[n]dd pp will paste deleted lines to current cursor

position

Page 53: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 53

Text Yanking Commands

Command Description

y character

y0 beginning to cursor position y$ cursor position to end of line [n]yw copy n words [n]yy n lines from current line in to the buffer [n]yy p p will paste copied lines to

current cursor position

Page 54: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 54

Text Manipulation Commands

Command Description

nc [space] overwrites next n characters with space

c0 overwrites the portion between beginning of line to cursor position

c$ overwrites the portion between cursor to end of line

Cw overwrites current word:%s/pattern1/pattern2/g globally replaces pattern1 with pattern2 on

the specified lines:%s/pattern1/pattern2/gc globally replaces pattern1 with

pattern2 on the specified lines interactively

Page 55: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 55

Text Related Commands

Command Description

ab <abb> <longword> set abbreviation for a long word

una string unset abbreviation>> right shifting a line<< left shifting a lineR replace characters starting with

current character till Esc is pressed

Page 56: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 56

File Related Commands

Command Description

ZZ or :wq save and exit:w save & continue editing:q! quit without saving:r filnam I insert contents of file

filename :[addr1,addr2]w filname write the lines between line

number addr1 and line number

addr2 in the file filename

Page 57: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 57

File Related Commands

Command Description

1,$s/source/target/ substitute string source by string target from line number 1to las line

u undo last change on the lineU undo last changes on the lineCtrl-R redo the undone changese edit multiple files e# return to previous file

Page 58: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 58

Customizing vi

set commands

Command Description

:set all displays all set option:set autoindent/ai does automatic indentation:set number/nu shows all line duly numbered:set showmatch helps to locate matching brackets:set tabstop=5 sets tab=5 for display:set ic ignore case while pattern matching

When the string “no” is prefixed to any option, it indicates that the option is inoperative

Page 59: CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1 History of Unix Developed in AT&T Bell Labs by Ken Thomson as a single user OS in 1969 Initially written.

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 59

Summary

In this session, we have covered: Unix Overview Unix File System Unix Commands Vi editor