Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Tuesday, July 04, 2006

bash history - ignore duplicate & commands

put these lines in your .bash_profile to ignore duplicate history or to ignore certain commands.
and it also keep your history short :)
# ignore duplicate
HISTCONTROL=ignoreboth

# ignore these commands in history file
HISTIGNORE=ls:ll:la:l:cd:pwd:exit:mc:su:df:clear

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

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