Tikejhya: Ashish Nepal

Knowledgebase

Category: Vi (Page 1 of 2)

vi advance commands

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

d0 delete from the beginning till the cursor

>> Indent line by shiftwidth spaces
<< De-indent line by shiftwidth spaces
5>> Indent 5 lines
5== Re-indent 5 lines

>% Increase indent of a braced or bracketed block (place cursor on brace first)
=% Reindent a braced or bracketed block (cursor on brace)
<% Decrease indent of a braced or bracketed block (cursor on brace)
]p Paste text, aligning indentation with surroundings

=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block

>i{ Increase inner block indent
Decrease inner block indent

Bash format option [disable autocommenting]

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#Bash format option [disable autocommenting]
:set formatoptions-=cro

vi copy from line number to line number

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

vi copy from line number to line number

You can use split, or sed

Lets use command sed for example

in below given example we have start line number: 143 end line number 201 and file name: filter.log
output to file called outfile.log

# sed -n '143,201p' filter.log > outfile.log

other way to achieve copy:
Block selection VI

Using marker we can achieve that too.

Type

mk

to mark this spot as

k

.
Go to the end of the section you want.

Type: y’k (y= Yank, , k) To yank from the mark to the current location.

Now p will do your job

Also you could use d’k to cut/delete.

Vi comment out block

Vi comment out block / VI comment multiple lines

Go to the line and hit

1) m{CHAR} or m{a}
and
2) put e mark in m{CHAR} in the end of the line

When you have marked a with start of line and e with end of line
type
3) :’a,’e s/^/# /

You can also use line numbers,
1 to $ ($ is the last line)
solitary % for everyline
. or blank for the current line.
To illustrate the “blank”, these two commands do the same thing:

:,$ s/^/# /
:.,$ s/^/# /

SED (remove last two character of the line)

Remove Last two character of the line

sed -e ':%s/..$//g'

This will remove last two character from all lines.

Delete files except/multiple

How to delete files except certain file or except multiple files.

rm -rf $(ls *|egrep -v “input|bar|script”)

umount device is busy

umount device is busy

Try this out.. :p
umount -l /dev/sdwhatever

Find with CentOS (Search)

Finding / Locating

locate
which
whereis

Search and list all files, in given directory and narrow search for given string..

find ./ -name "*" -exec grep -Hi "which string to search" {} ;

Find all user files larger than 5Mb:

find /home -size +5000000c -print

Find all files created or updated in the last five minutes: (Great for finding effects of make install)

find / -cmin -5

Find files modified in the last two days:

find / -mtime 2 -o -ctime 2

Disk Check/ Usages, Space, Filesystem type

df -k :::::::::report filesystem disk space usage. (-k reports in Kbytes)
du -sh :::::::::Calculates file space usage for a given directory. (and everything under it) (-s option summarizes)

Exiting Vi and going back

Suspend VI

control-z

Get back to your shell

fg

start a subshell using:

:sh

(as configured by)

:set shell?

or

:!bash

History (grep from history command)

Type the following command to get a list of all related commands with their history numbers:

history | grep -i “

Once you’ve found the command you want, you can execute it specifically by its number using the following built-in history expansion command:

!

Page 1 of 2

Powered by WordPress & Theme by Anders Norén