Posted by decipherinfosys on April 4, 2008
VI is most popular editor on UNIX. Today we will recap some of the most frequently used VI editor commands. To edit the file using VI, use vi filename. Following is the list of frequently used VI commands.
Single character commands:
a => append after the cursor
A => append at the end of the line
b => move back one word at a time.
B => move back last word before the space.
C => change entire line
e => move cursor at the end of the next word.
G => takes to the end of the file.
h => move one position on left
H => takes to the first line or top of the display screen. If it is preceded with number, then it takes you to that line. e.g. 5H takes to the 5th line from the top.
i => insert from current position or before cursor.
I => insert at the beginning of the line.
j => move one line down.
J => append the next line to the current line on which cursor is positioned.
k => move one line up.
l => move one position on right.
L => takes to last line or bottom of display screen.
m => set the mark. e.g. ma will mark current position as a. similarly we can use mb or mc etc. to mark different positions. Marked positions can be recalled from anywhere in the file using ‘a or ‘b or ‘c. ( ‘ is single quote key left of the <ENTER> key.)
n => repeat last search in forward direction. If you reach the end of the file, then search will again start from the beginning of the file.
N => repeat last search in backward direction. If you reach the beginning of the file, search will again start from the end of the file.
o => open the new line after current line.
O => open the new line before current line.
p => insert from buffer. (yanking ‘yy’ will put lines in buffer)
r => replace current character where cursor is positioned. It can be replaced by other single character.
R => replace characters from current position onward, one character at a time until ‘Esc’ key is pressed.
s => substitute current character. Substitution could be one or more characters.
S => substitute entire line.
u => undo previous change.
U => undo entire line.
w => move one word forward.
x => delete current character.
{ => move back one paragraph. Paragraph is considered as text between two blank lines.
} => move forward one paragraph
% => match the parenthesis
~ => reverse the case (if upper then do it lower and vice versa).
$ => move to last column.
. => repeat the last command.
0 => move to beginning of the line.
Esc => exit out of the edit mode.
Double character commands:
dd => delete the current line. If number precedes dd, then those many lines will be deleted. e.g. 10dd will delete 10 lines from current position.
cc => change entire line
yy => yank/copy the line in buffer. It can be placed in the file using p option. If number precedes yy, then those many lines will be copied in buffer. e.g. 10yy will copy 10 lines in buffer, which can be put into file anywhere using p.
cw => change word.
ce => change word.
ZZ => save changes and exit the file.
Commands with <Ctrl> Key:
Ctrl-l => refresh screen
Ctrl-b => move one screen backward.
Ctrl-f => move one screen forward.
Ctrl-g => status of the file.
These are some of the basic and frequently used commands used in VI editor. For a full reference sheet for the VI commands, you can just google for “vi commands” and you will find a lot of good concise information.
Posted in Unix | 1 Comment »
Posted by decipherinfosys on October 15, 2007
Sometimes, when we are working with the Oracle database, we come across the need to put files on remote server which are to be picked up by some other process or we have to ftp file(s) for backups. One can transfer the file manually by using ftp either to put on the remote server or to get it from the remote server. Manual process has its own disadvantage as it requires human intervention. We can always automate the process and schedule it as a cronjob so that script gets invoked at specific time and file transfer takes place automatically. Following is the small shell script which automates the process of putting the file on the remote server. Cut and paste following text on a UNIX machine and save it as a shell file (.sh extension).
#!/bin/sh
ftp_server=”10.80.10.27″
exp_dir=”/home/oracle/decipher”
ftp -n ${ftp_server} << EOF
user ftpuser ftpuser\*
cd /customerdb/ora_bkup
lcd ${exp_dir}
bin
put decipher_backup.dmp
EOF
• First line indicates that we are using bourne shell. This is default for UNIX. Shell is nothing but the command interpreter. It reads command from the key board and executes it. When more than one command is put together in the file, it is called shell script. We can execute the shell script which in turn will execute all the commands within the script.
• Second and third lines, we are declaring variable and assigning value to it.
• Fourth line we are invoking ftp connection with –n option. When –n option is used, it turns off the automatic login and ftp client will not ask for userid and password to connect to remote server. If not, then it will try to login immediately and will prompt for userid and password. ‘<< ’ is a redirection syntax and indicates that anything defined after this will be considered as an input to the ftp command.
• On the fifth line, we are giving credentials to login to the remote server by providing userid and password.
• On the sixth line we are changing the directory where we want to put the file.
• Seventh line, we are using lcd command to change the directory on local machine and hence (lcd), from which we would like to transfer the file.
• On the eighth line, we are changing the transfer mode to binary. Default is ascii mode. If it is a zip file or export dump file, it is advisable to transfer it in binary mode otherwise during transfer it may get corrupted.
• In the ninth line, we are using put command to put the file on the remote server.
• 10th line indicates EOF, means redirection is over at this point. So if at all, any other command is used in the script after this point will not be considered as an input and will be executed individually.
In similar fashion, one can get the file from remote server using get command. Script can be enhanced further to check for the success or failure of ftp process as well.
Posted in Oracle, Unix | No Comments »
Posted by decipherinfosys on June 10, 2007
It can get quite frustrating at times when you want to access files on your linux/unix machines which host your Oracle or DB2 LUW databases. MSFT offers a simple solution via the program suite called Services for Unix (SFU). Samba also has a suite of tools for UNIX systems for sharing files over the network with MSFT Windows. Here are a couple of resources to help you further to sort out file sharing issues:
http://samba.org –> Samba’s web-site and a lot of very good information and tools.
http://support.microsoft.com/kb/304040 –> Configuring File Sharing in Windows XP
Windows Services for Unix download - here and the homepage for SFU information - here.
Posted in Linux, Unix, Windows | No Comments »
Posted by decipherinfosys on February 23, 2007
Here is a cheat-sheet for the Unix commands to find swap, RAM and OS version on different Unix and Linux versions:
To Find Swap, RAM, and OS Version
OS SWAP RAM OS VERSION
———————————————————————————-
AIX /usr/sbin/lsps -a /usr/sbin/lsattr -HE -l sys0 -a realmem oslevel
HP swapinfo -q dmesg | grep -i mem uname -a
Tru64 swapon -s vmstat -P /usr/sbin/sizer -v
Solaris swap -s /usr/sbin/prtconf | grep -i memory uname -r
Linux free free uname -a
Posted in Linux, Unix | No Comments »
Posted by decipherinfosys on February 22, 2007
When do you categorize a server to be running into a CPU bottleneck? And how do you go about collecting that information on Windows and other Unix systems? The yard stick that is very commonly used is that if an individual user process is consuming greater than 10% of the CPU then there is a need to investigate further. Also, if the cumulative CPU usage is consistently more than 80%, then this also indicates a CPU bottleneck. If there are no individual processes using a lot of CPU, then you are trying to put too much work on the server, and should upgrade to either faster processors or add more processing power. Here is what you can do to automatically capture this information on different OS:
HP/UX or AIX or Linux or Solaris:
“sar –o <filename> 60 10 >/dev/null 2>&1 &” will sample the CPU activity every minute for 10 minutes and save the output in a file. If you are running into issues, reduce the time-frame for the data collection.
If user+nice+system > 80% for an extended period of time, then you have a CPU bottleneck.
AIX specific:
“vmstat 10 500″ will display system CPU usage every 10 secs. If id=0 or us+sy>80 for an extended period of time, then this indicates that the system is CPU-bound.
Solaris specific:
“top” will show you the top processes by CPU activity
Note: You may have to install SUNWaccu and SUNWaccr packages if sar is not installed.
Windows:
a) Use the task manager and select the processes tab.
b) Then click either the “CPU” column title to sort the processes
A better approach though is to use perfmon (Performance Monitor) and schedule it to collect the data:
c) Type perfmon from the command line (Start/Run and then perfmon and enter)
d) Then click on the “+” symbol and add “%processor time” for each of the processors you have on your system. You can save this as a blg file and then do further analysis on it later on.
Posted in Linux, Unix, Windows | No Comments »