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
command.
esc-p -- like ctrl-r lets you search through the previously
given commands.
esc-. -- gives the last command you typed.
tab -- auto completion
Read more...

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

note:
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
Read more...

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

conclusion:
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...

Saturday, February 25, 2006

unix tip: kill signal

this morning I had a problem starting up one program. from the error log its stated that the program exit with signal 6.
how do i know what is the signal 6 mean?
a friend of mine show me this :)
# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
30) SIGPWR 31) SIGSYS 33) SIGRTMIN 34) SIGRTMIN+1
35) SIGRTMIN+2 36) SIGRTMIN+3 37) SIGRTMIN+4 38) SIGRTMIN+5
39) SIGRTMIN+6 40) SIGRTMIN+7 41) SIGRTMIN+8 42) SIGRTMIN+9
43) SIGRTMIN+10 44) SIGRTMIN+11 45) SIGRTMIN+12 46) SIGRTMIN+13
47) SIGRTMIN+14 48) SIGRTMIN+15 49) SIGRTMAX-15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6
59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX

and for more info about the signal, use
# man 7 signal

eventhough i know what its mean now but still i can't figure out what is the problem with the program :(

Friday, February 24, 2006

unix tip: sort processes by cpu/memory usage

you can use the following commands to sort processes by cpu/memory usage.

linux
cpu:
# top -bn1P

memory:
# top -bn1M
or just type top without any options, you'll get an interactive interface.

solaris
cpu:
# prstat -s cpu

memory:
# prstat -s size
Read more...

aix
cpu:
# ps -ef | egrep -v "STIME|$LOGNAME" | sort +3 -r | head -n 15

memory:
# svmon -P
summary of the top 15 processes using memory on the system, use the following command:
# svmon -Pt15 | perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}'
or you can just use an topas.

Tuesday, February 14, 2006

unix tip: rename files - replace spaces with underscores

last week a friend of mine asked me how to rename a bunch of files that have spaces on its name.
this is what i came up with:
$ cat replace_spaces_with_underscores.sh
#!/bin/ksh
while read filenames
do
mv "$filenames" "`echo "$filenames"sed -e 's/ /_/g'`"
# use below line if you don't want to replace it with underscore
#mv "$filenames" "`echo "$filenames"sed -e 's/ //g'`"
done < filenames_with_spaces

but 1st u need to run this, dump filenames with spaces to one file:
$ ls grep " " > filenames_with_spaces

p/s: since i'm in nederland, maybe i should try their space cake :)