[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: find a command i have recently used in bash



* Jason Pepas (j.pepas@mail.utexas.edu) [030129 10:33]:
> On Wednesday 29 January 2003 08:21 am, Sandip P Deshmukh wrote:
> > let us say, i have done ls -l , etc etc
> > then i have done a few more commands at the prompt.
> >
> > now, i want to use that ls command again. is there a way inwhich i can
> > reach it quickly? for instance, i type ls and some other key and bash
> > completes from history?
> 
> you can use the up arrow to reach previous commands.  or you can grep your 
> .bash_history, like grep ls ~/.bash_history

The .bash_history is only written when bash is exiting, so it won't
include commands you recently typed within the same session.  That is to
say, it won't have anything since you most recently logged in.  It's
also prone to missing some commands from previous sessions as well, in
cases in which you had multiple sessions running concurrently.  This is
because bash reads ~/.bash_history when starting up, works with the
history in memory, then writes ~/.bash_history when exiting.

So let's say you're working in a few xterms.  You start one, and go like
this:

ls
cd ~/foo
cat bar

Then you start another xterm, with another bash, and do:

vi asdf.txt
cat aoeu.txt
exit

Then you go back and close the first xterm.  your .bash_history file
will not have the lines "vi asdf.txt" or "cat aoeu.txt" in it.

There are some shell options to change the precise bahavior of the
shell, but I believe I have illustrated the default behavior here.

I think the best way to do what OP asked is control-R.  man readline to
learn more about how your command line is way more powerful than
probably you previously imagined.

good times,
Vineet

-- 
http://www.doorstop.net/
-- 
One nation, indivisible, with equality, liberty, and justice for all.

Attachment: pgpG3vJtV5OWy.pgp
Description: PGP signature


Reply to: