Friday, April 23, 2010

File system

File System

Developer

Directory Contents

File Allocation

Third Extended Filesystem(EXT3)

Stephen tweedie

Hashed B-tree

Bitmap(Free space), Table(meta data)

New Technology File System(NTFS)

Microsoft

B+ tree

Bitmap

File Allocation Table(FAT)

Microsoft

Table

Linkedlist

Thursday, April 22, 2010

Questions

How does SVI(switch virtual interface) works?
How does default-gateway works??

Thursday, April 15, 2010

VIM



VIM 
 
:set -- To see current configuration of VIM
How to recover from swap:
1 Open the swap file .file.swp in vim
2 :recover will recover your file 

wrap:
set wrap -- to wrap lines to fit into window

Set highlight search color
set hlsearch
hi Search ctermbg=LightYellow
hi Search ctermfg=Red

Registry:
Registers in Vim let you run actions or commands on text stored within them. To access a register, you type "a before a command, where a is the name of a register. If you want to copy the current line into register k, you can type
"kyy
Or you can append to a register by using a capital letter
"Kyy
You can then move through the document and paste it elsewhere using
"kp
To paste from system clipboard on Linux
"+p
To paste from system clipboard on Windows (or from "mouse highlight" clipboard on Linux)
"*p
To access all currently defined registers type
:reg

Changing Color scheme
colorscheme default/morning/evening etc..

show scripts running under vim:
scriptnames

Block commenting:
1. Move to the first column in the first line you want to comment-out.
2. Press Ctrl-V to start block-mode selection.
3. Move down to select the first column of a block of lines.
4. Press I and then the desired comment starter (i.e. // or #)
5. Press ESC and the insertion will be applied to the whole block.
To uncomment with this techniques follow the directions but instead of I use x to delete the first char.

VIM diff:
To get the diff between current open file file1 and another file file2:
:vert diffsplit file2
To get the diff between two files files1 and file2:
:tabe file1
:vert diffsplit file2
To traverse between the diffs:
[c :Jump backward to the previous start of a change
]c: Jump forward to the previous start of a change

 vimdiff /path/to/file scp://remotehost//path/to/file

[[     --   Jump to funtion start.
[{    --   Jump to block start.
%    --   Jump to matching parenthesis.
=%  --  Indent code between parenthesis. 
*      --  Search the word under the cursor.

Multiple searches at same time:
/ \|

Multiple search & replace at same time:
:%s/aaa/bbb/e | %s/111/222/e

To white spaces(by default endof line is shown with '$' and tab as ^I):
:set list
:set list! --- no form of above command

Ex editor commands:
:e#     --  opens last opened files.
:ls       --  List the list opened files through vim.
:e#n   --  Will re-open the  nth opened file, listed in ":ls" command.

:b#     --  opens last opened opened file("Ctrl-6" does the same).
:bn      --  Will re-open the  nth opened file, listed in ":ls" command.
:b[TAB] -- Will list the buffers.
:b [any partof file name][TAB] -- auto completes the complete file name in the buffer.

Basic configuration of .vimrc
set nocompatible
set bs=2
set shiftwidth //No of spaces to be used for each step of (auto)indent.

Search ∧ Replace:
:%s/abc.*//gc -- remove trailing abc including abc from a line
:%s/abc\zs.*//gc -- remove trailing abc excluding abc
:%s/.*\ze\abc//gc -- remove leading abc excluding abc 
%s/.*abc/abc/ -- remove leading abc excluding abc
:%s/.\{-}abc/abc -- remove leading abc excluding abc fist occurrence
%s/.*\ze\<undefined\>//g  --- remove leading abc excluding undefined.
 
%s/<[^>]*>//gc  -- replace angular bracket contents to different string
g!/<pattern>/d -- delete lines which doesn't match pattern
 
:put =range(1,100)  -- set number on each line


%s/\s\+$//  -- remove  all spaces and tabs at the end of the line

 :.,$s/pattern1/pattern2/gc  -- to find and replace from the current location to end of the file.
:1,.s/pattern1/pattern2/gc -- to find and replace from start of the file to current location.

Add a word at particular coloumn at all lines of the file
 
set ve=all
Go to the column number
Ctrl-v
select number of rows we need to copy.
press r
type the character
escape
Done :-) 

-----------------------------
word completion: 
ctrl-x ctrl-n -- Word completion – forward
CTRL-x CTRL-p -- Word completion – backward

 
Ctrl+x Ctrl+l -- line completion
 
Ctrl+x Ctrl+f -- file completion
  
set dictionary+=/usr/share/dict/words  -- dictionary words

Ctrl+x Ctrl+k -- dictionary word completion
 
 

set nocompatible: This option stops vim from behaving in a strongly vi-compatible way. It should be at the start of any vimrc 
file as it can affect lots of other options which you may want to override.
*****************************************
Syntax highlighting not working in vim:
Just check your vim runtimepath settings by giving following command:
:set rtp
Check whether your runtimepath path info has the same vim version location 
as your vim version if not change the path location to your vim version.
For example:
if the ":set rtp" is 
set runtimepath=~/.vim,/usr/share/vim/vim63/macros/vimfiles,/usr/share/vim/vim63,/usr/share/vim/vim63/macros/vimfiles/after,~/.vim/plugin
but your vim version is vim7.0 then change the runtimepath to following:
set runtimepath=~/.vim,/usr/share/vim/vim70/macros/vimfiles,/usr/share/vim/vim70,/usr/share/vim/vim70/macros/vimfiles/after,~/.vim/plugin
*****************************************
TO grep in VIM:

in ex editor

: grep -rin "label" *
This will give the results in buffer. If you type "ENTER" there, you will be taken to first item in the search list.
To traverse through the all the items of the search. type ":cscope" on ex editor which will open the buffer.
You can use the arrow keys to traverse the buffer & to the item press "ENTER".
Other option to move between the search items is use ":cn" and ":cp"

To get Help from VIM, try
:h

To traverse between the tags use "ctrl-t" and "ctrl-]"

Ctrl-[ can be used as alias to ESC key to enter command mode
:set wildmode=longest,list -- This will find the longest match with the first 'wildchar', then list all matching files with the next.
:set ai -- To set auto indentation.
:history -- to see the history of commands in ex-mode
:history / -- to get search history of vim.
q: -- in the normal mode to open history of commands window. You can search/edit here using regular vim commands. You start in Normal mode. Press 'Enter' to execute a command.
:u -- undo changes.
Ctrl -R -- redo changes.
ga -- show ascii value of character under cursor in decimal, hex, and octal.

Follow the follow commands to indent total file: gg=G
gg -- to go to the top of file
= -- To fix the indentation
G -- Perform the operation till the end of the file.

Ctrl-w c -- Make buffer hidden and close window.
Ctrl-w q -- Quit editing and close window
Ctrl-w o -- Make current window only one on the screen.
Ctrl-w s -- Splits the window Horizontally.
Ctrl-w v -- Splits the window Vertically.
Ctrl-w w -- To navigate between the windows.
Ctrl-w ] -- Split window and jump to tag under cursor
Ctrl-w n -- Create new empty window
Ctrl-w r -- Rotate windows downwards.
Ctrl-w R -- Rotate windows upwards.
CTRL-W x -- Exchange current window with next one
Ctrl-w = -- Make all windows equal height
CTRL-W - -- Decrease current window height
CTRL-W + -- Increase current window height
CTRL-W _ -- Set current window height (default: very high)


 :h quickfix -- Command help for Vim's special mode to speedup the edit-compile-edit cycle. :h csqf -- Help commands for Vim's cscopequickfix commands
VIM on windows:

Saving font & color setting on gvim -
First, specify your font by going to Edit > Select Font (btw, I'm on a Windows machine, so maybe the linux menus are different).

Second, after you've selected your font, enter the command :mkvimrc!. This will write your font choice (and key mappings, etc) to your _vimrc file. This will NOT save your color settings if you're using a theme, however. To tell gVIM to use a color theme at startup, go to the next step.

Third, to specify your color theme, enter the command :e _vimrc. This will open your VIM settings file for editing. Scroll to the bottom of the file and add the line "colors blue". You can specify whatever color theme you want in place of "blue", provided you use the name of the theme itself. No file references are necessary. And it's case-insensitive too, so you could enter "colors Elflord" or "colors elflord" and be fine either way. Just make sure you write the file to disk before you quit gVIM.

Windows GVIM:
.vimrc equivalent file can be found at: Edit > Startup Settings
:vimgrep -- equivalent grep command used
:cs -- to list the grep'd results 
Config:
colorscheme koehler
set wildmode=longest,list

References:
http://www.scribd.com/doc/33619079/VIM-%E2%80%93-VI-Improved
http://www.fprintf.net/vimCheatSheet.html
http://www.linuxquestions.org/questions/programming-9/how-to-save-gvim-settings-307945/
http://www.catswhocode.com/blog/100-vim-commands-every-programmer-should-know 
http://www.lilax.net/textfiles/2001-06-09/vim_multifile.html 
http://www.kevinberridge.com/2008/10/vim-file-editing.html 
http://www.openlogic.com/wazi/bid/188018/Vim-Undo-Tips-and-Trickshttp://www.openlogic.com/wazi/bid/188018/Vim-Undo-Tips-and-Tricks
http://vimdoc.sourceforge.net/htmldoc/cmdline.html#history 
http://vim.wikia.com/wiki/VimTip1572 --- highlight
http://stackoverflow.com/questions/6225291/vim-delete-all-text-in-line-before-after-highlighted-search-pattern 
https://stackoverflow.com/questions/1497958/how-do-i-use-vim-registers?rq=1
https://stackoverflow.com/questions/7103173/vim-how-to-change-the-highlight-color-for-search-hits-and-quickfix-selection

Tuesday, April 6, 2010

cygwin

Backspace problem with vim in cygwin:
a) Make sure you are in nocompatible mode, ":set nocp"
b) Check your 'backspace' setting. ":set bs=2" should allow you to
backspace normally in insert mode.




References:
http://comments.gmane.org/gmane.editors.vim/33436

Thursday, March 25, 2010

Firefox

Firefox shortcuts:

Back one Page: "Backspace"
Go Down One Screen : "PageDown" or "Spacebar"
Go Up One Screen: "PageUp" or "Shift+Spacebar"

References:
http://www.7is7.com/software/firefox/shortcuts.html

Monday, March 22, 2010

Pine

Pico Editor

Pico, short for Pine Composer, started life as the built-in editor for the Pine email program. Lots of people use Pico as a text editor because they also use the friendly Pine program for email.

PINE

By default, Pine automatically checks for new mail every 2.5 minutes. (You can change this time interval with the mail-check-interval option in the SETUP CONFIGURATION screen.) Some system administrators may have globally modified this interval.

When viewing the FOLDER INDEX, you can force Pine to check for new mail by pressing ^L, or if on the last item in the Index, by pressing "N". The eXpunge command will also force a new-mail check. If you would like to have some visual indication of when Pine is checking for new mail, set the enable-mail-check-cue feature and watch for an asterisk to flash in the upper-left-hand corner of the screen. (Two asterisks mean that Pine is check-pointing --saving state changes in-- your INBOX.)

jump to start of line : ctrl-a

jump to end of line : ctrl-e

page-down : ctrl-v

page-up : ctrl-y

jump to bottom : ctrl-w ctrl-v

jump to top : ctrl-w ctrl-y

set mark (for copy) : ctrl-^

cut line (or marked text) : ctrl-k

paste : ctrl-u

delete : ctrl-d

backspace : Backspace

delete : backspace (yup, you read that right, depends on your terminal settings)

wrap text : ctrl-j

search : ctrl-w

replace : (NOTE pico needs to be started with -b for this to work) ctrl-w ctrl-r

spell-check : ctrl-t (note that pico needs to be started with -s ispell for this to work), I add this line to my .profile: alias pico='pico -s ispell' so that this can be done automatically.

get cursor position - ctrl-c

insert an external file : ctrl-r

exit (will prompt to save) : ctrl-x

sort threads : $ h

delete/mark as read all messages : ; then a then a then *


General config in .pinerc:

user-domain=domain.com
default-fcc="{email.domain.com/user=username}Sent Items"
postponed-folder={email.domain.com/user=username}Drafts
rsh-open-timeout=0
inbox-path={email.domain.com/user=username}INBOX
smtp-server=outbound.domain.com


References:

http://www.blogger.com/post-create.g?blogID=5997165761357298829

http://www.washington.edu/pine/


Friday, March 19, 2010

GNU Screen

 Screenrc

caption always
#caption string "%{kw}%-w%{wr}%n %t%{-}%+w"
caption string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "

Ctrl-a : -- will take you to the GNU SCREEN command mode(vim kind of ex mode)

Ctrl-a :altscreen on/off -- To clear/not screen up on exiting from vim/less/man
Ctrl-a :number -- To renumber current terminal with newer one, incase a terminal exist with new number,
                  it   will take the current terminal number.
Ctrl-a :A -- To rename the current window
Ctrl-a :hardcopy -h [filename] -- copy entire contents of scrollback buffer
Ctrl-a :H       Begins/ends logging of the current window to the file "screenlog.n".
Ctrl-a :log [on|off] -- Begins/ends logging of the current window to the file "screenlog.n".
Ctrl-a :logfile filename -- Setting filename for logging.
Ctrl-a :logfile flush [secs] --  is used to set delay between each write to the logfile, by default it’s 10 seconds.

Configuring the Scrollback Buffer

By default, the scrollback buffer only keeps the last 100 lines of text, which is not enough for my typical interaction with Screen. I’ve found a setting of 5000 lines to be more than adequate for my usage. The number of scrollback lines can be configured in your $HOME/.screenrc file, by adding the following line:
defscrollback 5000
This sets the scrollback to 5000 lines.
You can also override this default value when starting screen using the -h [num] option, where num is the number of scrollback lines.
Finally, if you want to change the number of lines of scrollback for a single window, using the “scrollback” command. Hit C-a (Ctrl-A) : to go to the Screen command line and type scrollback num, where num is the number of scrollback lines.
In screen search to turn off case:
C-a :ignorecase off/on
Problem: GNU got struck because of mistakenly pressed "ctrl-s"
Solution: Ctrl+s “tells the system not to send any more data to the screen until a ctrl-q is pressed”. so pressing ctrl-q will solve the problem here :-)
References:
https://bbs.archlinux.org/viewtopic.php?id=55618
https://wiki.archlinux.org/index.php/GNU_Screen
http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer/
http://www.gnu.org/software/screen/manual/screen.html
http://aperiodic.net/screen/commands:start 
http://superuser.com/questions/137714/using-screen-commands-like-less-and-man-dont-clear-the-screen-afterwards/137751#137751 
http://serverfault.com/questions/244294/gnu-screen-how-to-re-order-windows-change-the-scroll-shortcut-and-modify-th 
https://github.com/saltycrane/homedir/blob/master/etc/.screenrc