Tuesday, June 27, 2006

Linux Snippets.

Linux command tips ******
http://www.pixelbeat.org/cmdline.html


http://www.felixgers.de/teaching/emacs/vi_search_replace.html

Vi: Search and Replace
Change to normal mode with .

Search (Wraped around at end of file):

Search STRING forward : / STRING.
Search STRING backward: ? STRING.

Repeat search: n
Repeat search in opposite direction: N (SHIFT-n)

Replace: Same as with sed, Replace OLD with NEW:

First occurrence on current line: :s/OLD/NEW
Globally (all) on current line: :s/OLD/NEW/g
Between two lines #,#: :#,#s/OLD/NEW/g
Every occurrence in file: :%s/OLD/NEW/g
Command for commenting out N number of lines (N = number of lines) :.,+N s/^/#/g
-----------------------------------
awk and sed commands

file test.txt content is retheesh kumar R
to view kumar R use
#cat test.txtawk '{print $2 $3}'

or you can use sed command and remove retheesh
#cat test.txtsed 's/retheesh//'
this switches retheesh with blank //

vi +5 filename.txt # This will open the filename.txt with the cursor on the 5th line
vi +$ filename.txt # This will open the filename.txt with the cursor on the last line

=========================
Edit Multiple files at one go.
==========================

vi file1 file2 file3
Will open file1
:wnext to move to file2 by saving changes to file1
:next! to move to file2 without saving changes on file1

To move to previous file
:wprevious - To move to previous file by saving changes to the current.
:previous! - To move to pervious file without saving changes to the current

To see the list of file that is being edit and to know the current edite
:args

========================================
Viewing mulitple file on the same vim window
======================================

To split multiple files for easy editing. (Horizontal Split)
vim fileone #original file from the original file type
:split /path/to/filetwo # Another file
Will open up 2 different files you can toggle between both the files using CTRL + W
To save changes type
:wclose - Will save changes to the file
:close! - Will exit without any changes

To split multiple files for easy editing. (Vertical Split)
im fileone #original file from the original file type
:vsplit /path/to/filetwo # Another file
Will open up 2 different files you can toggle between both the files using CTRL + W
To save changes type
:wclose - Will save changes to the file
:close! - Will exit without any changes

================================
New file from existing vim window
===============================
Creat a new txt file from vi console
:new - Will create a new file for edition
Note while saving ensure to use :w filename to save the file
======================
Command to manually set date on the redhat system.

#date -s "MM/DD/yyyy hh:mm:ss"
Example -
#date -s "03/17/2006 02:01:39"
-----------------------------------
For better graphical display during bootup and on command line mode edit grub and
add " rhgb quite vga=0x317"

eg: kernel /vmlinuz-2.6.9-5.EL ro root=LABEL=/ rhgb quiet vga=0x317
---------------------------------

Procedure to register and up2date your machine.

#cat /etc/redhat-release -----------> will show the redhat version you are using

up2date-nox --config
httpProxy :
enableProxy Yes

#up2date-nox -l
This will connect to the server using the proxy details mentioned, and sent the server details to the rhn.redhat.com site. (tab systems).
#run the rpm -keyXXSSXXSSSS
execute command to start updating the packages to the latest
#up2date-nox -u -----------> will start updating all the packages with the latest packages available on redhat site.

Using up2date command to update kernel.
Note: Kernel update will not actually upgrade the kernel but install a new version of kernel and make relevent entries on the /etc/grub.conf file and set the boot parameter to boot with the new kernel.
#up2date-nox -f kernel -----------> either enter kernel* or manually give all the kernel-smp, kernel-Highmem etc to install.

#cat /etc/redhat-release -----------> will show the updated redhat version
--------------------------------------

mke2fs -j -b 4096 / will specifiy 4KB blocksize, this will help in faster fsck.


No comments: