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 &

Monday, August 12, 2013

Kill a process with ease

Well normally you will have to find the process id in order to kill it
eg. kill - 9 1234

But there are alternatives to it such as
  • kill -9 `pidof processName`
  • kill -9 `pgrep processName`


Get any music gratis with just few clicks and a plugin

Sounds crazy doesn't it ? Isn't that a hell lot of piracy ? or is it even legal ?

Well those were some thoughts that echoed in my brain too ! But its happening on grooveshark.com where in you can simply search for any song you can practically think of , even the one's in your native lang. Its a pretty awesome service but I wonder how it is legal :? , a look at the entry of grooveshark's
Wikipedia pages shows lawsuits liabilities to be of astronomical 17 Billion dollars :O .


Though the groovy's app has been official removed from google's play store and thwarted from facebook , its still thriving and growing with the crowds pouring in to its recently launched personal broadcast channel power by user suggestions. There is even third party created plugin that help you download any song on grooveshark with just one click.


Sunday, August 11, 2013

Vim : Actually numbering the lines

You can always display line numbers inside vim with :set nu , little did I know of a way of actually inserting the line number inside the file .

Here is a cool trick for line numbering

  • Number all the lines in Vim

    • :%! cat -n 

  • Number only a portion of file contents
    • First enter the Vim visual mode by pressing v
    • select the portion that you want to number
    • then :'<,'>!cat -n





Saturday, August 10, 2013

Direct terminal output to vim

  • command | vim  -
  • e.g ls | vim -  and then :save fileName to store it.

Friday, August 9, 2013

git update remote origin

git update remote origin
It might happen during  addition of the repository origin that you typed an incorrect URL ( happened to me :P ) .  In such cases you will get an error like this
just update the remote origin with this command

  • git remote set-url origin <URL>

Wednesday, August 7, 2013

Need to copy directories from your computer to laptop ?

Ssh is handy in such cases , all you need to do is

  • scp -r userName@ipAddress:/path/to/folder destinationFolder
  • e.x scp -r vihaan@192.168.0.1:~/Downloads/eclipse .
  • "." refers to the current directory.


Tuesday, August 6, 2013

Word wrap the contents of a file

    • :set wrap
How to open a file in Read Only mode

    • vim -R fileName
Typing a big command on Terminal ?

Why don't you try reverse-i-search  feature built in the terminal. Just press Ctrl + R and only a unique part of the big command that you have already executed before.

Here is how I start eclipse on my system just by typing 'ec'
You might find a problem associated with reverse search that it just searches in the reverse direction and once your are past what you were searching for , your efforts are rendered useless.

There is a solution around this and you can enable forward search by some modifications.

  • Open up .bashrc and add the following lines in it 
    • stty -ixon
  • refresh the bash setting by executing
    • source .bashrc
Now you will be able to search forward using Ctrl + s .
Dot Files

Make Vim even better with some dot files ( https://github.com/sontek/dotfiles ).
Handy Vim shortcuts

  • Line Numbers
    • Set line number with
      • :set nu
    • Unset line numbers with
      • :set nonu
    • Set relative line numbers with 
      • :set relativenumber.

  • Copy selected lines from vim visual mode to system clipboard.
    • "+y and then paste it outside vim.

  • Make vim paste the content from outside properly.
    •  :set paste
  • unfold code
    • zo
  •  fold code  
    • zc 

        Tuesday, July 30, 2013

        Forgetting  Sara Mouse ( pun intended)

        There is a utility out there called as QuickTile which basically help you define key mapping for managing your windows with ease. You need to have python installed to get this thing working on you system , which you will find to be similar to Compiz Gird and Unity's window placement with super and arrow keys but QuickTile is more simpler and customizable.

        You can customize the config file ~/.config/quicktile.cfg to your needs. I have chosen ALT to be the action key along with vim like key binding for window movement. If your interested you can clone the quicktile.cfg file from my repo present at https://github.com/VihaanVerma89/configFiles
        Shutdown / suspend /hibernate your Linux machine with commands

        If you are a fast typist you and a terminal addict you might want to shutdown/hibernate/reboot your machine the CLI way. Here are some of the commands that will help you do the same

        Shutdown
        > sudo poweroff

        Hibernate
        > sudo pm-hibernate

        Suspend
        > sudo pm-suspend


        World Domination using terminal effectively
        Are you a developer running many terminals simultaneously and having a tough time managing em ?

        Back at my work I was facing this problem of having to ALT + TAB multiple instances  of many terminals , I gave Screens a try but the keyboard mapping is very hard to get adjusted to . Recently I have come across the Terminator , its pretty handy as its keyboard mapping are very intuitive and easy to grasp. Check out the snap and learn the mapping using man terminator.


        Monday, July 29, 2013

        Sed file manipulation
        Consider you need to replace an occurrence of a word across multiple files , what do you do ?
        Now you can open up each file in vim and do a search and replace in each file but that's an inefficient way of doing it.

        Sed to the rescue
        Sed is a file manipulation tools that can help in such situations. With just one command you will be able to replace all words across multiple files.

        here is how you replace "word1" with "word2" in current directory

        sed -i "s/word1/word2/g *
        Test