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

Re: find a command i have recently used in bash



On 29 Jan 2003 15:54:32 -0600,
Ron Johnson wrote:
> 
> On Wed, 2003-01-29 at 10:28, Nathan E Norman wrote:
> > On Wed, Jan 29, 2003 at 07:51:07PM +0530, Sandip P Deshmukh wrote:
> > > hello all
> > > 
> > > i am sure there must be a way of doing it. i am not getting it though.
> > > 
> > > 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?
> > 
> > If you're using bash, and the command you want to retrieve was typed
> > in the last 500 or so commands, try "ctrl-r ls" which should recall
> > the most recent command with the string "ls" in it.
> > 
> > You can also use the "history" command to view your history.  Any
> > command in your history can be reused by prefixing its history number
> > with a bang ('!').  Thus if history says "422  ls -lAF /usr/local" you
> > can type "!422" at a prompt to issue that command again.  history +
> > grep can be fun.
> 
> I find this a helpful refinement:
> $ history | sort -rn | less

tcsh has a far more elegant (tm) approach to the problem. Typing
"ls<ALT-P>" (or META-P) will get you only all the commands that
begin with "ls" (eliminating such oddities as "echo lst.txt"). If
somebody knows the precise bash equivalent of this, let me
know. BTW AFAICT the tcsh equivalent of CTRL-R is a wildcard
sequence like "*ls*", which will capture all *ls* whether command
or argument.



Reply to: