Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Sunday, November 28, 2010

Power of vi editor Linux

Power of vi Editor
=========
# vim /home/shirish/myscripts/scratcher.sh <-- colorfull look
# vi  /home/shirish/myscripts/scratcher.sh  <-- simple
Moving through the text is usually possible with the arrow keys. If not, try:

h -> move Left
l  -> move Right
k -> move up
j -> move down

shift+H : top of file  (or :1 similarly you can go to any line by line number(n) :n)
shift+G : end of file (or :$)

dd       --> delete current line
5+dd   -> delete 5 line from current line (similarly n line)
5+dw   -> delete 5 words from current word
x         -> delete single character from current position
cc        -->cut all current line  content & leave the editor in insert mode
C         --> delete all words from current position to end of line.
s         -->cur the current character and leave te curser in insert mode

yy       -->copy line
n+yy   --> copy n lines
pp       -->paste copied line etc..
n+pp   -->paste n times

Insert Mode:
1> i   or I (cpas i)
2> Insert button
3> a (+move curser to 1 position right)
4> A (+ move the curser at end of line)
5> o  (+ a blank line below current)
6> O (+ a blank line above current)

Command mode:  ESC button

:w   -> Save
ESC+z+z --> Save & exit
:wq  -> Save & Exit
:q    -> Exit
:q!   -> Exit without Save
:w file2 will save the text to file2.
:wq! overrides read-only permission
/find  -->Search string "find"  use "n" to search new location
? find --> same as above but search in opposite dir
:1, $s/shirish/shukla/g  -->replace shirish by shukla throught file

undo & redo:
esc+u --> undo
ctl+r   --> redo
esc .  --> repeate the previous change

Bookmark

step 1> Go to the required word (type ESC+ma) you can use any lowercase  a - z, A - Z, [  ect,..   note that a & A store diff bookmarks etc..
step  2>To go to bookmarked location (type ESC+ `+a  ) note ` is above TAB button, similarly you can give various bookmarkes
* You can go to yu last edited line by -->  ESC+`+ .

:marks   --> Will show  your bookmarks in current file.

Quick Summary of Vim Bookmark Commands

    * ma –> Creates a bookmark called a
    * `a   –> Jump to the exact location (line and column) of the bookmark a
    * ‘a   –> Jump to the beginning of the line of the bookmark a
    * :marks –> Display all the bookmarks
    * :marks a –> Display the details of the bookmark with name a
      `. –> Jump to the exact location (line and column) where the last change was performed
    * ‘. –> Jump to the beginning of the line where the last change was performed

Advanced:

K --> Go to the man page of the word currently under the curser.

How to schedule cron job Linux

Schedule Crontab jobs

Crontab
It's a unix solaris utility that tasks to be run automatically in background at regular interval.
Daemon: crond

Accessibality:
/usr/lib/cron/cron.allow -> Use can use if your name exist in this file
In absence of this file it's necessary that your name does not exist in
/usr/lib/cron/cron.deny.
And If only cron.deny exist but empty then all users can use crontab.
But if neither exists only root can use crontab.

Commnad:
crontab -l ->List crontab file
crontab -e ->Edit crontab file
crontab -r ->Remove crontab file

====Crontab file fields

* * * * * command to be executed

|  |  |  |  |
|  |  |  | +----- day of week (0 - 6) (Sunday=0)
|  |  | +------- month (1 - 12)
|  | +--------- day of month (1 - 31)
|  +----------- hour (0 - 23)
+------------- min (0 - 59)

Example:
0> Edit crontab for root 
# Login as root
# crontab -e


1>Edit crontab for user shukla
# crontab -u shukla -e

2>Display crontab defined by user shukla
# crontab -u shukla -l

3>Delete shukla's tmp file /home/shukla/dumps/*.* every day at 3:30pm
# crontab -u shukla -e
30 15 * * * * rm /home/shukla/dumps/*

4>Do above every monday-wednesday at 3pm but only in mnth of august
# crontab -u shukla -e
* 15 * * 8 1-3 rm /home/shukla/dumps/*

5>Do above on 1,23 of aug
* 15 1,23 * 8 1-3 rm /home/shukla/dumps/*

6>Do Above at 10:10AM and 6:20pm everyday...
10,20 10,18 * * * rm /home/shukla/dumps/*

7> Sample tricky examples
>Run Every hour
0 * * * * ....
>Run every min
* * * * * * ....

 >Run every 5 min
*/5 * * * *  .....

>Run ever 2 hour interval eg:00:05, 02:05
5 */2 * * *

>Ever month except april
* * * jan-mar,5-12 * * OR
* * * 1-3,5-12 * *

>On every reboot display msg alert
@reboot wall "PC is going to REBOOT"

>Ever hour same above --->this will run 1st sec of every hr equivalent to (0 * * * *)
@hourly wall "PC is going to REBOOT"

Some similar too:
@yearly --> (0 0 1 1 *)
@annually --> (0 0 1 1 *)
@monthly --> (0 0 1 * *)
@weekly --> (0 0 * * 0)
@daily --> (0 0 * * *)
@midnight --> (0 0 * * *)

--Shirish Shukla

Thursday, November 18, 2010

Linux History command tips & Tricks

History Command Tips:

1>Generally # history displays only commands you tiped last Suppose you want time too then...?

# export HISTTIMEFORMAT='%F %T '
# history | more
1  2010-11-11 15:05:20 top
2  2010-11-11 15:05:25 man top
3  2010-11-11 15:05:29 free -m
4  2010-11-11 15:10:05 cat /proc/mdstat

2>Search last hosory by ctl+r and type command you typed in last
when comes just press enter or use arrow to edit and fire you command

#Press Ctrl+R from the command prompt,
(reverse-i-search)`man ': man Top
[Note: Press enter or edit as per your requirement]

3>#Repeat you previou command quick
way 1> use up arroy once
way 2> !!   <- Enter
way 3> !-1  <- Enter
way 4> ctl+p <-Enter

4> quick sortcut
#!5  <- 5th commnds you used from history to check use #history |less
#!man <- latest commnad you used that started with man...
#export HISTCONTROL=ignoredups (ignore duplicates commnds from history)
#export HISTCONTROL=erasedups  (remove duplicates commnds from history)
#export HISTCONTROL=ignorespace (ignore to add cmnds starting with space in history)
eg:
#export HISTCONTROL=ignorespace
#  man dig
#history
1 pwd
2 man top
3 ...
but history does not store any command you start with space

5> Clear your history
# history -c

6> Disable to use of history
# export HISTSIZE=0
# history
no o/p

7> Enable history to not record specifics commnands
# export HISTIGNORE="man:ll:pwd:password:alias amgreat=clear:amgreat"
Now use above commands but history dosent save it.
   
8> control you history size ..
# vi /home/yourhome_dir/.bash_profile
HISTSIZE=450
HISTFILESIZE=450

Followers

Pls LIKE my Story !!!