Tuesday, December 8, 2009

accessing history of commands in bash

1. the most common is using !! , CTRL+P or !-1 to access the previous command typed. use !$ to retrieve all parameters for the previous command
2. CTRL+R on terminal allows you to search for a command with a keyword, you can do the same using !
3. there are several global variables controlling the history file, its size, name, allowance for duplications etc.
HISTSIZE - number of history lines
HISTFILESIZE - actual file size limit of the history file
HISTFILE - edit the actual history file used
HISTCONTROL - controls whether history allows duplicates, if not, how to eliminate them. option ignoredups erase consecutive repeating commands, erasedups erase all commands that arn't unique, ignorespace option sets all commands started with a space to be not shown in history
4. you can use an positive index to specify which history command you want to execute from the top of the history file, or negative index if from the button of the history file. history -c cleans up the history of your shell