Sunday, March 20, 2011

Linux Usage: Turn on Bash Smart Completion

Bash shell provides an awesome feature that increase the accessibility in command line. Some files' name are long and you probably won't want to type it or maybe you type it wrong easily. Auto-completion is a good function for you which you just need to type a few characters only. For example, you can type

$ cd Dow [press tab key]

it will help you to complete the command to

$ cd Downloads

Sometime, bash shell can't identify your file name since there are multiple files with same initials. For example, you type
cd Do [press tab key]
You may see
Documents        Downloads
Then now you need to input more key to specify the file name

In fact, bash shell in ubuntu is smarter now, you can find that codes which enable smart completion in the bashrc file.
if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

If you view /etc/bash_completion, it defines which program to use which file type. For example,
complete -f -X '!*.@(pdf|PDF)' acroread gpdf xpdf
which means for program "acroread", "gpdf" or "xpdf", when you press tab key under bash shell, it will find files with pdf or PDF extension only.

However, you may find that for sqlite3, the default support extension is .sqlite. Sometimes, I use .db as sqlite3 file. Thus I changed it to
complete -f -X '!*.@(sqlite|db)' sqlite3

Monday, March 7, 2011

Vim Usage: spell checking

Yesterday, I needed to type a document using Latex. This is better to use Latex for document works especially for those needed proper layout. Latex provide a good layout function comparing with MS Word. However, for me, I probably will make many typo error and in fact I typed lots of misspell word yesterday. Sometimes it is easy to find out but sometimes not. MS Word provides spell checking already. Fortunately, Vim 7 provides this function also. To enable it, use ":set spell" in command mode. To turn it off, type ":set nospell". If you are using Vim in terminal, you can see the misspell words are highlighted. You can use move key to go to the wrong words and fix them. In fact, you can use "]s" that is a useful function which moves the cursor to the next misspelled word. To move to previous misspell word, use "[s". When your cursor in over the wrong word, you can press "z=" to ask Vim to provide suggestions. I tried that and I found Vim spell checking are quite accurate, most likely the first one will fix my typo. If you want more information about spell checking function, use ":help spell" to read the documentation.

  • "]s" - move to the next mispelled word
  • "[s" - move to the previous mispelled word
  • "zg" - add a word to the dictionary
  • "zug" - undo the addition of a word to the dictionary
  • "z=" - view spelling suggestions for a mispelled word

Thursday, March 3, 2011

Ruby on Rails: Application - Tracks

I am a person who really needs a task management system. Otherwise, I will forget lots of important stuff and my time table will not be so optimal. Before using web-based application, I used Getting Things GNOME (GTG) which is popular in Linux system. GTG also supports Remember the milk so that you can synchronise your job list with different computers. However, I always forgot to click the sync button and the job list goes messy right now. Thus, I try to find something which is online as I have a Linux server in my office. Then, I found Track (http://www.getontracks.org/) which is implemented with Ruby on Rails. Tracks is a web-based application to help you implement David Allen’s Getting Things Done™ methodology. This is open-source project so you can design your own style and functionalities if you know Ruby on Rails. It has a built-in webserver which is WEBrick (I suggest to use Mongrel as I found WEBrick has some problems when I access the web page), so that you can run it on your own computer if you like. With this application, I can edit my tasks in a centralised way, and I don't need to worry about the synchronisation problem. Once my server didn't dead, I still can view and edit my schedule.

Tuesday, March 1, 2011

Linux Usage: ping? Not enough, we have a more powerful tool - fping

fping - send ICMP ECHO_REQUEST packets to network hosts

fping is a program like ping which uses the Internet Control Message Protocol
(ICMP) echo request to determine if a target host is responding. fping differs
from ping in that you can specify any number of targets on the command line, or
specify a file containing the lists of targets to ping. Instead of sending to one
target until it times out or replies, fping will send out a ping packet and move
on to the next target in a round-robin fashion.

In the default mode, if a target replies, it is noted and removed from the list of
targets to check; if a target does not respond within a certain time limit and/or
retry limit it is designated as unreachable. fping also supports sending a speci‐
fied number of pings to a target, or looping indefinitely (as in ping ).

Unlike ping, fping is meant to be used in scripts, so its output is designed to be
easy to parse.

Installaton:
$ sudo apt-get install fping

Usage:
$ fping [options] hosts

Useful Options:
  • -a Show systems that are alive.
  • -A Show systems that are alive
  • -c Number of request packets to send to each target. In this mode, a line is displayed for each received response (this can suppressed with -q or -Q)
  • -C Similar to -c, but the per-target statistics are displayed in a format designed for automated response-time statistics gathering
  • -d Use DNS to lookup address of return ping packet
  • -f Read list of targets from a file. This option can only be used by the root user. Regular users should pipe in the file via stdin: $ fping < targets_file
  • -q Quiet. Don't show per-target results, just set final exit status
  • -rn Retry limit (default 3)
  • -Tn Select timeout in seconds (default 10)
  • -u Show targets that are unreachable
Exit Code (DIAGNOSTICS):

  • 0 if all the hosts are reachable
  • 1 if some hosts were unreachable
  • 2 if any IP addresses were not found
  • 3 for invalid command line arguments
  • 4 for a system call failure.
Conclusion:
fping send ping request continuously which is simpler and faster than ping that send to destination one request by one request.

Monday, February 28, 2011

Linux Usage: solution for installing debian deb in ubuntu

Sometimes, we will download debian deb and installed it under ubuntu. If you are lucky, this will be okay and the installation will go normally. However, it may report errors like:
The package XYZ needs to be reinstalled, but I can’t find an archive for it.

XYX is the name of your deb package.

At that time, you can remove the wrong package using the following command in terminal:
$ sudo dpkg –remove –force-remove-reinstreq XYZ