Friday, March 31, 2006

bash tip: search command history

from my previous post on ksh hotkeys vs bash hotkeys, i mentioned on how to use hot key to do search on command history, which is using ctrl-r
but i also mentioned that i'm not sure on how to use this key to go to the next or previous match command. i found it now :)

once you hit ctrl-r to do a "reverse incremental search". as you type, bash will search your command history and auto-fill the most recent command that matches the pattern you type in. hit ctrl-r again to go to the next most recent match. just hit ctrl-r again & again until you found the command you looking for. and if you want to go the previous match command, you can hit ctrl-s, but make sure you do this first:

disable the default terminal setting for ctrl-s & ctrl-q which is to lock & unlock your terminal.
$ stty -ixon

Thursday, March 30, 2006

shell tip: which shell you currently using

how do you tell which shell you currently using?

just use:
$ echo $0
$ bash
$ echo $0
$ csh
% echo $0
% zsh
% echo $0

Wednesday, March 29, 2006

shell tip: setting environment variables

below is the compilation on how to set environment variables for different shells

sh, ash, bsh, ksh, zsh, bash & bash2:
to set use - export TEST=test123
to unset use - unset TEST

csh, zsh & tcsh:
to set use - setenv TEST test123
to unset use - unsetenv TEST

is there any other shell out there?

guest blogger for

i've been invited by editor from itechtips to be guest blogger for his site.
check it out here

Tuesday, March 28, 2006

linux tip: change date

last time when i want to change the date/time, i use date command with this option:
date MMDDhhmm

$ date
Mon Mar 27 17:41:37 CEST 2006
$ date 03271630
Mon Mar 27 16:30:00 CEST 2006
but i found an option which much more easier:
$ date
Mon Mar 27 16:30:15 CEST 2006
$ date -s "Mon Mar 27 17:45:15 CEST 2006"
Mon Mar 27 17:45:15 CEST 2006
just copy & paste the current date & edit it.

Thursday, March 23, 2006

unix tip: find a character position in word

somebody asked on how to find a character position in a word/line on the forum

the question:
how to find a character position in a word/line?
Unix forum is the best site.

now in above line i want to find the character 'x' position
i.e 4

this is what i came up with:
$ echo "Unix forum is the best site." | grep -o "[-_a-zA-Z0-9\.]" | grep -n x
one of the users has a very simple solution:
$ expr index "Unix forum is the best site." x

Tuesday, March 21, 2006

cool stuff: pose nude in public

do you dare to nude in public? me, i don't think so, but not for these 1500 venezuelans. they just nude in public for photo shoot :P

CARACAS, Venezuela -- More than 1,500 Venezuelans shed their clothes on a main city avenue on Sunday to pose for Brooklyn photographer Spencer Tunick, forming a human mosaic in front of a national symbol: a statue of independence hero Simon Bolivar.
As Tunick shouted commands through a megaphone, nude people of every shape, size and skin tone gathered on the avenue and stairs in front of the statue just before dawn.

this is the picture from nederland local newspaper, in front page! enjoy :)

script: determine variable type

i found this useful script on how to determine the variable type.
$ cat mad.ksh
#! /bin/ksh

[[ -z "$1" ]] && echo "I cant work without an input" && exit 1


[[ "$INPUT" == ?(+|-)+([0-9]) ]] && echo "$INPUT is numeric" && exit 0

[[ "$INPUT" == +([a-zA-Z]) ]] && echo "$INPUT is character" && exit 0

[[ "$INPUT" == *([0-9]|[a-zA-Z])* ]] && echo "$INPUT is alpha-numeric" && exit 0

$ ./mad.ksh 123
123 is numeric
$ ./mad.ksh abc
abc is character
$ ./mad.ksh abc123
abc123 is alpha-numeric

i hope they don't mind i paste it here.

Saturday, March 18, 2006

i amsterdamed!

my friends from aberdeen, scotland came over here for 2 weeks training & on that weekend i brought them to visit what they called "sex & drugs" city - amsterdam.
image hosting by
so our mission is to find out whether those are for real :P

one of the nederland landmarks - windmill taken from train on the way to get there.
image hosting by
we reached here in the afternoon so we don't have enough time to explore everthing. but got a chance to visit couple of their museums which is amsterdam historical museum & sex museum. aha! we found the sex part already. are you sure? hehehe nope, there is another best part & i'm not going to tell you. go figure!

actually we can just walk around in this city, but as the weather is killing us, we just took tram instead. to our suprise mas advertisement on their tram :) should we be proud? hmmm...
image hosting by

i'm a chess player, hmmm actually yahoo! games chess player :P. my friend dfhzn told me there is a giant chess in the leidseplein. here you go, while waiting for them to finish the game. as expected, white lost! but not really a giant lorr...
image hosting by
just behind us is the amsterdam hard rock cafe.

actually we were planning to stay over night here, so that we can continue the exploration tomorrow, but all the hostels or even hotels are fully booked and some hotels don't even want to rent it out since we only want it for 1 night. hampeh!
just before we heading back home, we took a break & breath in their coffeeshops. as you all may know or don't know, this is the drugs part. actually they are just a regular coffeeshops, we can have coffee, tea, cappucino or whatever that in the menu but there are some special things in the menu as well. coffeeshops here are allowed to sell small amounts of cannabis or marijuana. they have it in the cake aka spacecake and also in coffee or tea even in hot chocolate. so be carefull with what your order or you'll end up with red eyes & stoned :)
image hosting by
nah... we just had our regular coffee daa... :P

Wednesday, March 15, 2006

skiing in de uitholf

this is me 1st time skiing in de iutholf.
at first, it was very hard to get it balance & i fell down most of the time :P

but at last managed to get it right... it was really fun & cold of course!

hmmm maybe i'll try snowboard next time, look far more cool than ski. but they said snowboard much more harder to learn than ski... hmmm i guess i have to give it a try then :)

unix tip: sendmail - email not been sent out but queued

ever come accross with this problem? when you try to sent out email, the email can't be sent out but get queued instead!!!
# cat filename | /usr/sbin/sendmail -v queued

somehow, sendmail by default will check the system load average
before sent out the email. if the load average exceeds QueueLA (default 8),
it stops delivering the mail, if load average exceeds RefuseLA (default 12)
it stops accepting the mail. both of the settings are located in

even you increased the value, sendmail still not works as its will give an error below.
# ps auxw | grep sendmail
root 6519 0.0 0.0 6252 2040 ? S 12:52 0:00 sendmail: rejecting connections on daemon MTA: load average: 77

so you need to set the value higher, but i'm not so sure about this.
this is my system load average: quite high huh!!!
# uptime
3:01pm up 96 days, 23:09, 15 users, load average: 78.10, 77.86, 77.57

of course you can manually flush/sent out the emails from the queue by using command below:
# /usr/sbin/sendmail -OQueueLA=80 -q 0 -v

but in this case i suggest you take a look at your system load & if possible try to decrease the load.

it took me a few days to find out this thing since there was no error message about the load average, but if you're lucky you'll get this "sendmail: rejecting connections on daemon MTA: load average:" in your log files which make easier to google :)

QueueLA default values is (8 * numproc) where numproc is the number of processors online (if that can be determined).

Tuesday, March 07, 2006

unix tip: file test operators

i always keep forgetting these file test operators, so i decided to paste it here for my future reference :)
-r file check if file is readable.
-w file check if file is writable.
-x file check if we have execute access to file.
-f file check if file is an ordinary file (as opposed to a
directory, a device special file, etc.)
-s file check if file has size greater than 0.
-d file check if file is a directory.
-e file check if file exists. Is true even if file is a

if [ -s file ]
such and such

for more info, go here

Friday, March 03, 2006

unix tip: ksh hotkeys vs bash hotkeys

a few of our servers are running ksh shell instead of bash. sometimes i have
problems handling ksh hotkeys because getting used to bash hotkeys like below:

bash hotkeys:
ctrl-l -- clear screen
ctrl-r -- does a search in the previously given commands so that
you dont have to repeat long command.
ctrl-u -- clears the typing before the hotkey.
ctrl-a -- takes you to the begining of the command you are
currently typing.
ctrl-e -- takes you to the end of the command you are currently
typing in.
esc-b -- takes you back by one word while typing a command.
ctrl-c -- kills the current command or process.
ctrl-d -- kills the shell.
ctrl-h -- deletes one letter at a time from the command you are
typing in.
ctrl-z -- puts the currently running process in background, the
process can be brought back to run state by using fg
esc-p -- like ctrl-r lets you search through the previously
given commands.
esc-. -- gives the last command you typed.
tab -- auto completion

below are the hotkeys when i'm using ksh shell (you have to
set -o vi first)

ksh hotkeys:
esc-\ -- auto completion. only work if the file/command is in
current directory
esc-k -- scroll up
esc-j -- scroll down
esc-/ -- search in the previously given commands (esc-/ keyin
the command you want search & enter. press n or N to
go to the next or previous command, even ctrl-r in bash
can't go to the next or previous command or maybe i just
don't know how.
esc-= -- filename check - this is cool!!!

since its using vi mode, you can also edit the commands
using below keys
esc-l -- forward one character
esc-h -- backward one character
esc-x -- delete one character
esc-r -- replace one character
esc-e -- forward end of word
esc-b -- backward beginning of word
esc-d -- delete to end of line
esc-i -- insert text (current space)
esc-a -- insert text (adjacent space)
esc-^ -- move cursor to beginning of line
esc-$ -- move cursor to end of line

esc key is not necessary if you are currently in command-mode

Thursday, March 02, 2006

unix tip: wildcard - asterix (*) vs question mark (?)

ever wonder what is the different between asterix (*) and question mark (?) when you use them as wildcard?
here are some examples:

list all the files
$ ls
fileA fileAA fileAAA fileB fileBB fileBBB fileC fileCC fileCCC

if you use * it will listed all files
$ ls *
fileA fileAA fileAAA fileB fileBB fileBBB fileC fileCC fileCCC

but if using ? it will not
$ ls ?
ls: ?: No such file or directory

list all files that start with file
$ ls file*
fileA fileAA fileAAA fileB fileBB fileBBB fileC fileCC fileCCC

but if you use 1 ? it will listed only files that start with file+1 character
$ ls file?
fileA fileB fileC

same goes when you using 2 or 3 ?
$ ls file??
fileAA fileBB fileCC
$ ls file???
fileAAA fileBBB fileCCC

the asterix (*) is to replace zero to multiple characters while the question mark (?) only to replace a single character & of course you can use them with other commands as well such as find, grep etc...