Unix Blink

59
8/22/2019 Unix Blink http://slidepdf.com/reader/full/unix-blink 1/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 in assembly language Developed as multi-user OS later Rewritten in C in 1973 Licensed to university for educational purposes in 1974

Transcript of Unix Blink

Page 1: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 1/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 1

History of Unix

Developed in AT&T Bell Labs by Ken Thomson as a singleuser 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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 2/59

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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 3/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 3

Features of Unix

Multi-user

Multi-tasking

Portable

Interactive

Hierarchical File System

Page 4: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 4/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 4

Unix Architecture

Hardware Kernel

Shell & UnixUtilities

OtherApplicationProgram

Page 5: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 5/59

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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 6/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 6

File Basics

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

File is just a sequence of bytes.

The meaning of the bytes depends solely on the programsthat interpret the file.

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

Page 7: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 7/59CONFIDENTIAL© 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 thedirectory but other attributes like file-size, permission, links,time-stamps are stored in the inode.

Page 8: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 8/59CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 8

File Types

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

1. Ordinary/Regular files

2. Directory files

3. Device/Special files

4. Symbolic links

Page 9: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 9/59CONFIDENTIAL© 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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 10/59CONFIDENTIAL© 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 theitem, and a numerical reference to the location of the item,called inode number.

Inode number is an index to a table known as the inodetable. Inode stores all information about the file except itsname.

Page 11: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 11/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 11

Device File

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

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

Two types of device files:1. Character Special

2. Block Special

Page 12: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 12/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 12

Symbolic Link

Links make the same file available in multiple directories atthe same time

Two types of Links:1. Hard Link

2. 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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 13/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 13

Inode

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

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

Page 14: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 14/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 14

Inode

 

Page 15: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 15/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 15

Pathname

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

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

Pathnames can be absolute or relative.

Page 16: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 16/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 16

Unix Users

Super User

Owner

Group

Others

Page 17: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 17/59

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 otherusers

Page 18: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 18/59

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 specificgroup is referred to as other user

Owner of a file can decide what permissions to be given toother users

Page 19: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 19/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 19

Unix Commands

Page 20: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 20/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 20

Basic Commands

$ pwd

Shows working i.e current directory

$ who

Shows who is logged on

$ who am I

Shows the login name of the current user

Page 21: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 21/59

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 thecommands called the sections. Sections are numbered from1 through 9. For example, commands are 1, system calls are2, library function are 3, file formats are 5, & managementcommands are 8.

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

The command man 2 open displays the manual for the

system call open.

Page 22: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 22/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 22

Basic Commands

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

For example,$ date

$ date –r TestFile

Displays the last modification time of the file “TestFile”  

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

Page 23: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 23/59

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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 24/59

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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 25/59

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 integersas well as floats

bc is a filter command

$ write user1

Lets to write a message to the other user; user1 in thisexample

Page 26: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 26/59

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 subdirectoriesencountered

-a list all files including hidden files

-i List all files along with i-node number

Page 27: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 27/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 27

Wild Card Characters

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

? – single Character -ex ls m? lists all the files starting withm 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 filesnot starting with any character from the range x-z

Page 28: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 28/59

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 lineone 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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 29/59

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 thecurrent directory

Page 30: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 30/59

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 thedest_directory

Page 31: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 31/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 31

File Management Commands

mv command changes name of the file or moves the file tothe 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 newdest_directory

l C d

Page 32: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 32/59

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 specifieddirectories and also the directories themselves

C i Li k

Page 33: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 33/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 33

Creating Links

ln file1 file2

Creates a hard link to existing file file1 with the name file2 inthe 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

Fi di Fil d Di t i

Page 34: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 34/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 34

Finding Files and Directories

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

Command Syntax:

$ find path criteria action

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

Fi di Fil d Di t i

Page 35: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 35/59

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 itssubdirectories

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

Fi di Fil d Di t i

Page 36: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 36/59

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 directoryand its subdirectories, and then prepares a copy of each filewith .bak extension

Fil C i

Page 37: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 37/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 37

File Comparison

comm compares two sorted files and produces result inthree colums:

Lines: Unique to file1 Unique to file2 Common

$ comm file1 file2

Anil 12 2000

Ajit 12 2000

Dinesh 27 1400

Sunil 12 2000

Fil A P i i

Page 38: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 38/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 38

File Access Permissions

chmod command is used to change the permissions on a filefor owner, group and others

chmod <permission><filename>

Symbolic Method:

Code Meaning

a all

u userg group

o other

+ add

- remove= assign

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

File Access Permissions

Page 39: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 39/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 39

File Access Permissions

Absolute value Method:

Code Meaning

4 Read2 Write

1 Execute

$ chmod 754 sample

File Access Permissions

Page 40: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 40/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 40

File Access Permissions

umask command changes initial permission of newly createdfile

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

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

$umask 0 – sets default mode which is 0666

Pipes

Page 41: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 41/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 41

Pipes

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

e.g. $ ls >temp

$ more temp

Ls | moreInput Output

| $ ls | more

pipe

Filters

Page 42: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 42/59

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,…) 

Filters

Page 43: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 43/59

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: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 44/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 44

vi Editor

The vi editor

Page 45: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 45/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 45

The vi editor

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

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

vi is extremely powerful in moving around within (or

between) files

The vi editor

Page 46: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 46/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 46

The vi editor

A vi session begins by invoking the command “vi” with afilename

$ vi [filename] 

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

The last line in the screen is reserved for some commandsthat you can enter to act on the text. This line is also usedby the system to display messages.

Modes of Operation

Page 47: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 47/59

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 passthe commands to act on the text, using most of the keys of thekeyboard

You can switch to this mode using “Esc” key

Insert (Input) mode: To enter the text, you have to enter intoinput 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 toanother file or make a global substitution in the file. You then

have to use ex mode, where you can enter the instruction inthe last line of the screen. To enter into this mode, press “Esc” key followed by “:”  

Text Insertion Commands

Page 48: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 48/59

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 lineo opens line below current line to insert text

O opens line above current line to insert text

Cursor Movement Commands

Page 49: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 49/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 49

Cursor Movement Commands

Command Description 

h left by one character

l right by one character

k up by one line

 j down by one linew right by one word

b left by one word

0 or ^ beginning of line

$ end of line

Cursor Movement Commands

Page 50: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 50/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 50

Cursor Movement Commands

Command Description

ctrl+u move up half window

ctrl+b move up full window

ctrl+d move down half window

ctrl+f  move down full window

ctrl+e scroll down

ctrl+y scroll up

Text Search Commands

Page 51: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 51/59

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

Text Deletion Commands

Page 52: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 52/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 52

Text Deletion Commands

Command Description

x character under cursor

X character before cursor

[n]dw delete n words

d0 beginning to cursor position

d$ or D cursor position to end of line[n]dd n lines from current line

[n]dd pp will paste deleted lines to current cursorposition

Text Yanking Commands

Page 53: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 53/59

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 tocurrent cursor position 

Text Manipulation Commands

Page 54: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 54/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 54

Text Manipulation Commands

Command Description

nc [space] overwrites next n characters with space

c0 overwrites the portion betweenbeginning of line to cursor position

c$ overwrites the portion betweencursor to end of line

Cw overwrites current word

:%s/pattern1/pattern2/g globally replaces pattern1 with pattern2 onthe specified lines

:%s/pattern1/pattern2/gc globally replaces pattern1 with

pattern2 on the specified lines interactively

Text Related Commands

Page 55: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 55/59

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 line

R replace characters starting withcurrent character till Esc ispressed

File Related Commands

Page 56: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 56/59

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 numberaddr2 in the file filename

File Related Commands

Page 57: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 57/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 57

File Related Commands

Command Description

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

u undo last change on the line

U undo last changes on the lineCtrl-R redo the undone changes

e edit multiple files

e# return to previous file

Customizing vi

Page 58: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 58/59

CONFIDENTIAL© Copyright 2008 Tech Mahindra Limited 58

Custo g

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 patternmatching

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

Summary

Page 59: Unix Blink

8/22/2019 Unix Blink

http://slidepdf.com/reader/full/unix-blink 59/59

y

In this session, we have covered:

Unix Overview

Unix File System

Unix Commands

Vi editor