Sunday 26 July 2015

vi editor commands

$ vi <filename>

Option ==> Action
vi     ==> Starts editing session in memory.
vi     ==> Starts session and opens the specified file.
vi *   ==> Opens first file that matches the wildcard pattern. Use :n to navigate to the next matched file.
view   ==> Opens file in read-only mode.
vi -R  ==> Opens file in read-only mode.
vi -r  ==> Recovers file and recent edits after abnormal abort from editing session (like a system crash).
vi +n  ==> Opens file at specified line number n.
vi +   ==> Opens file at the last line.
vi +/  ==> Opens file at first occurrence of specified string pattern.

Common Techniques to Enter vi Insert Mode:
Enter Insert Command ==> Action
i ==> Insert text in front of the cursor.
a ==> Insert text after the cursor.
I ==> Insert text at the beginning of the line.
A ==> Insert text at the end of the line.
o ==> Insert text below the current line.
O ==> Insert text above the current line.

Useful vi Exit Commands
Exit Command ==> Action
:wq ==> Save and exit.
ZZ  ==> Save and exit.
:x  ==> Save and exit.
:w  ==> Save the current edits without exiting.
:w! ==> Override file protections and save.
:q  ==> Exit the file.
:q! ==> Exit without saving.
:n  ==> Edit next file.
:e! ==> Return to previously saved version.

Common Navigation Commands
Command               ==> Action
j (or down arrow)     ==> Move down a line.
k (or up arrow)       ==> Move up a line.
h (or left arrow)     ==> Move one character left.
l (or right arrow)    ==> Move one character right.
Ctrl+f (or Page Down) ==> Scroll down one screen.
Ctrl+b (or Page Up)   ==> Scroll up one screen.
1G ==> Go to first line in file.
G  ==> Go to last line in file.
nG ==> Go to n line number.
H  ==> Go to top of screen.
L  ==> Go to bottom of screen.
w  ==> Move one word forward.
b  ==> Move one word backward.
0  ==> Go to start of line.
$  ==> Go to end of line.

Common Options for Copying, Deleting, and Pasting Text
Option ==> Action
yy  ==> Yank (copy) the current line.
nyy ==> Yank (copy) n number of lines.
p   ==> Put yanked line(s) below the cursor.
P   ==> Put yanked line(s) above the cursor.
x   ==> Delete the character that the cursor is on.
X   ==> Delete the character to the left of the cursor.
dw  ==> Delete the word the cursor is currently on.
dd  ==> Delete current line of text.
ndd ==> Delete n lines of text
D   ==> Delete to the end of the current line.

Common Options for Changing Text
Option ==> Action
r  ==> Replace the character that the curser is on with the next character you type.
~  ==> Change the case of a character.
cc ==> Delete the current line and insert text.
C  ==> Delete to the end of the line and insert text.
c$ ==> Delete to the end of the line and insert text.
cw ==> Delete to the end of the word and insert text.
R  ==> Type over the characters in the current line.
s  ==> Delete the current character and insert text.
S  ==> Delete the current line and insert text.

Common Options for Text Searching
Option ==> Action
/ ==> Search forward for a string.
? ==> Search backward for a string.
n ==> Repeat the search forward.
N ==> Repeat the search backward.
f ==> Search forward for a character in the current line.
F ==> Search backward for a character in the current line.

:set number ==> Displaying Line Numbers

u ==> Undoing a Command

September 30, 2013
Script to Gather data from the Linux OS
#####################################################################
###   Unix script os_stats.sh                                     ###
###   Designed to be run periodically to collate information      ###
###   START OF SCRIPT                                             ###
#####################################################################
#
LOG_FILE="OS_`hostname`_`date '+%m%d%y_%H%M'`.txt"
#
echo "**********************************************" >$LOG_FILE
date >> $LOG_FILE
echo "Running as  `id`" >> $LOG_FILE
echo "**********************************************" >>$LOG_FILE
echo "uname -a" >>$LOG_FILE
uname -a >>$LOG_FILE
cat /etc/issue >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "ulimit -a" >>$LOG_FILE
ulimit -a >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "ulimit -Ha" >>$LOG_FILE
ulimit -Ha >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "Netstat -i" >>$LOG_FILE
netstat -i >> $LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "netstat -an">> $LOG_FILE
netstat -an >> $LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "netstat -s">> $LOG_FILE
netstat -s >> $LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "sar -u 5 3">> $LOG_FILE
sar -u 5 3 >> $LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "sar -q 5 3">> $LOG_FILE
sar -q 5 3 >> $LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "ps -e -w -o user,pid,ppid,s,pcpu,pmem,vsz,rss,stime,time,args" >> $LOG_FILE
ps -e -ww -o user,pid,ppid,s,pcpu,pmem,vsz,rss,stime,time,args >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "iostat -t -x" >> $LOG_FILE
iostat -t -x >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "df -h" >> $LOG_FILE
df -h >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "mpstat 5 3" >> $LOG_FILE
/usr/bin/mpstat 5 3 >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "vmstat 5 3" >> $LOG_FILE
vmstat 5 3 >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "free -m -s 5 -c 3" >> $LOG_FILE
free -m -s 5 -c 3 >>$LOG_FILE
grep MemTotal /proc/meminfo >>$LOG_FILE
grep SwapTotal /proc/meminfo >>$LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
echo "IPCS data" >> $LOG_FILE
ipcs -l >> $LOG_FILE
echo "            ----------------------------         " >> $LOG_FILE
ipcs -u >> $LOG_FILE
echo "            ----------------------------         " >> $LOG_FILE
ipcs >> $LOG_FILE
echo "            ----------------------------         " >> $LOG_FILE
ipcs -t >> $LOG_FILE
echo "++++++++++++++++++++++++++++++++++++++++++++++++" >> $LOG_FILE
#####################################################################
###   END OF SCRIPT                                               ###
#####################################################################

No comments:

Post a Comment