Monday, August 26, 2013

Command History:

Any command executed on the machine gets logged. By default on bash the history size is 1000 commands. You can check your current size by

  • $ echo $HISTSIZE
this setting is stored in .bashrc , if you open it up you ll see something like this
  • HISTSIZE=1000 
It a good idea to increase the HISTSIZE to store a large number of commands, which can be rendered for quick execution with reverse-i-search.

There is also an interesting hack/trick around this :) . 
You can override the logging behavior but prefixing every command with a space. Interestingly commands executed in such fashion do not show up in the output of the 'history' command.

Also command history can be disabled by setting

  • HISTFILESIZE=0
in .bashrc

Wednesday, August 21, 2013

Change default OS the hacker way

Well I had played with grub.cfg long time back but recently I had to install Ubuntu on my laptop which I rarely use ( as I believe kick ass developers don't work on laptop :P ) and especially with window$ on it.

So anyway , I installed Ubuntu but forgot to set the default OS to window$  , well you might be like


Yeah yeah , I tried persuading my family members to use Ubuntu but soon gave up on them :P.

A very shiny pearl of wisdom I have picked up is that , always create a backup of any config file you plan on tweaking.

So lets go ahead and make a original backup of the /boot/grub/grub.cfg file which will be changed to reset the default options.


  • cd /boot/grub/
  • sudo cp grub.cfg grub.cfg.org
  • sudo vim grub.cfg
  • search for set default with vim search i.e "/set default" this is generally line 13 in grub.cfg
  • All the entries in the grub are associated with "menuentry" keyword in grub.cfg , for setting the default to windows OS we need to find the menuentry number for windows , these menuentry  starts with 0. If you are dual booted there are high chances that menuentry for windows would be 4.
    here in my case it has to be 4 , so I can change my default OS to window$ by pointing the default to 4.
  • change the set default to the corresponding OS menuentry , for me it is 


    • set default = "4"
    • optionally while you are at it , you can even make the booting faster by changing the default time out to 2 sec or so.
You can always use GUI grub config tools but 

Saturday, August 17, 2013

Grep : recursively search for the occurrence of a word in files.

Lets assume we are trying to search word "this" in all the files in the present directory. Would it be nice if I could see which all files it occurs in along with the line number. Passing some options to grep commands helps to do the exact same task.


Thursday, August 15, 2013

CLI: Quick command execution

There are very handy shortcuts available on the command line , lets just list em out.


  • Execute last command
    • $ !!
    • well this feature is really useful when you want to execute last command again but with sudo privileges.
      • $ sudo !!
  • Go forward/backward command history with Ctrl+n and Ctrl+p.
  • Access the last command argument with Alt + .
  • Use reverse-i-search by pressing Ctrl+r to search the history in reverse order.
Vim: Sort the file contents

Lets say you have a file that looks like this

and all you want to do is get the content rearranged in sorted order. Well here is a quickie , enter visual mode by pressing v , press Shift+g to select entire file and then just execute the sort command.
and bang here is the sorted content.

Tuesday, August 13, 2013

Design Pattern : Command Pattern

Well this is the first time I have put efforts to see how my code look from design point of view using ObjectAid UML tool available for eclipse. Neat ! isn't it :P

Above figure shows a type of behavioral design pattern called Command Pattern in which an object is used to encapsulate the information needed to call a method of "Reciever" at a later time.

The sample code for is present on the github repo.
Bash : Start a process in background

$ Command &
e.g vihaan@trojan:~$ google-chrome &