Monday, April 13, 2009

Commonly used switches in grep

grep cheat sheet
------------------
-i : ignore case
-w : Match the exact word
-A n : displays n lines after the match
-B n : displays n lines before the match
-C n : displays n lines on both sides of the match
-v : inverting the match
-e : for including multiple matches ( extending the match)
-c : counting the number of match
-l : displays only the file name of the match
-o : displays only the matched string
-b : displays the position of the match in the file
-n : line number will be displayed along with the match

Sunday, April 12, 2009

Timestamp with history

$ history
can be used to retrive the history of commands. It may be beneficial to display the timestamp along with the command for auditing purpose. HISTTIMEFORMAT variable can be used to achive the purpose
$ export HISTTIMEFORMAT=’%F %T ‘
Now the out put of the 'history' will be similer to this

Include the variable in your appropriate shell initialization file to make it permanent.