Home » Bash scripting, Featured

Tweak with Bash

13 January 2008 365 views 6 CommentsEmail This Post Email This Post

This Post is very special to the bash lovers,which also includes me .I’m trying to put very special commands i use normally,at a place.So here I go:
1.Past commands:
Press ctrl+r when the terminal is opened and you can get the past commands entered recently,matched with your letter.
This method is far better than pressing up key like a mad donkey.
Ex: press ctrl+r at bash prompt ull get sumthing like (reverse-i-search)`’: ,
now if u want ln -s /home/kranny/firefox/firefox ./firefox to be run,just type ln,and it will find u the command if it is typed recently….

2.My most fav:
Pressing Esc brings up the last object you referred to.If you had just typed cat /etc/apt/sources.list , then typing gedit then pressing esc . would auto complete to gedit /etc/apt/sources.list.i jus luv this…

3.Spelling Mistakes are annoying me:
Many times i type clera for clear and the msg “command not foun” annoys me….Just add the foll lines to ur .bashrc:
shopt -s cdspell
and spelling mistakes are ignored

4.werz my history?
When u type some commands ina terminal and Btw open a new terminal, the new one won’t remember any of the commands typed in the first one and moreover closing the first terminal, and then the second will overwrite any of the commands typed in the first terminal.Again this annoys!!!!The reason for this is that the bash history is only saved when you close the terminal, not after each command.Just add these lines to bashrc
shopt -s histappend
PROMPT_COMMAND=’history -a’
This makes bash append history instead of overwriting it, and makes it so that each time the prompt is shown it writes out all the history.

5.curly brackets {}:

I use this most of the times.If u want to make a copy of any files in the same/diff dir whose path is quite lengthy

Ex:cp /var/cache/apt/archives/aa.conf /var/cache/apt/archives/aa.conf_backup

can be replaced with cp /var/cache/apt/archives/aa.conf{,_backup}

PS 1:if u have any comment me,if they are worth using,ill update the post

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 2 out of 5)
Loading ... Loading ...

6 Comments »

  • Blumare said:

    I use bash also as calc:
    echo $((2+2))

    or

    echo 2+2 | bc

    That’s useful for bash scripting too

  • matthew said:

    Its a wonderful post ,i must say…this is a Nice Place to be around..

  • sriram said:

    Gr8 Post…thanks

  • Avinash said:

    Nice Collection of tips

  • Pradeep said:

    Thanks a lot

  • Virtualsoul said:

    Second tip is really Beautiful…Thanks

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.