CLI: Command History

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 06/10/05


Date: Fri, 10 Jun 2005 19:43:59 GMT

CLI="Command Line Interface"

One of the most useful features of a modern shell like bash
(although it did 'borrow' this feature from the old C shell), is
the command history.

When you enter commands at the prompt, bash keeps a record of
them, which you can see by entering:

history

See those numbers? If you want to run one of the commands,
enter:

!N

where "N" is the number before it.

To find a command that you made, the best way (unless
it was very recently used) is to use Ctrl-r (^R), and then enter
the first letter or two. If it doesn't show up right away, hit ^R
again until it does, or add the next letter.

When the right command shows up, just hit Enter.

^R is a backwards search through the history file.

^P and ^N move back and forwards through the history file from
wherever you are. (up/down arrows will do the same thing)

^U and/or ^K will clear the prompt.

Needless to say, the history file can get really cluttered,
and fortunately there are ways to keep the clutter down.

(history -c will delete every entry in the history file)

Put these in your ~/.bashrc:

export HISTCONTROL=ignorespace

export HISTIGNORE="ls:cd:&"

and have bash reread the file with:

source ~/.bashrc

HISTCONTROL=ignorespace

That means that any command you run that you
don't want to be recorded in your history file
can just be preceded by a space.

HISTIGNORE="ls:cd:&"

That's a list of patterns (you can use shell
wildcards) that you want to be kept out of
your history file. Short ones that you use
all the time. The "&" means to ignore duplicates.

AC

-- 
alanconnor AT earthlink DOT net
Use your real return address or I'll never know you
even tried to mail me. http://tinyurl.com/2t5kp
~


Relevant Pages

  • Re: Switching from tcsh to bash as an interactive shell
    ... >> Anyone care to clue me in as to some of the neato features bash has over ... But isn't that what tcsh does? ... I have never been able to make out how bash history ... Bits of command appear and disappear, and I don't know if one ...
    (comp.os.linux.misc)
  • Re: OSR 6.0
    ... I have an SCO OSR 6 server and I would like the "history" feature like linux ... command line editing such as bash or ksh. ...
    (comp.unix.sco.misc)
  • Re: intelligent unix shells
    ... >> I issue the same command several times it still only shows up once as ... >> the last command in the history, ... question was about "unix shells(csh, bash, sh)". ...
    (comp.unix.shell)
  • Re: OSR 6.0
    ... even better that I can also do like run straight from history by doing ... | command line editing such as bash or ksh. ... The default root shell ...
    (comp.unix.sco.misc)
  • Re: bash history
    ... I notice that bash doesn't save every command ... immediately and loses the history from simultaneous bash sessions, ...
    (Debian-User)