LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   The "History" Command? (https://www.linuxquestions.org/questions/linux-general-1/the-history-command-615611/)

carlosinfl 01-22-2008 07:39 PM

The "History" Command?
 
I recall my old work colleague show me a history command that allows you to search the history for all commands that started with lets say "wget" or whatever you're looking for rather than everything in your history cache. I attempted a Google search and could not find anything that shows me how to refine the history search.

Anyone know what I am looking for?

rkelsen 01-22-2008 07:44 PM

grep?

It works like this:

cat ~/.bash_history | grep wget

carlosinfl 01-22-2008 07:50 PM

Quote:

Originally Posted by rkelsen (Post 3031950)
grep?

It works like this:

cat ~/.bash_history | grep wget

Thanks - that does the trick however I recall there being a command with in the history command that allows you to do the same thing w/o using "grep"

Either way, it appears the results are the same...

anomie 01-22-2008 08:08 PM

You also might check out the event designator "!", which lets you quickly print (with or without executing) the most recent command that starts with a certain string.

Contrived example:
Code:

[fugu ~]$ history
  11  file /etc/sysconfig/iptables
  12  ls
  13  top
  14  history
[fugu ~]$ !file:p
file /etc/sysconfig/iptables

The :p modifier tells bash to print but not execute the command.

In any case, that still doesn't sound like quite what you're looking for; check out the extensive manpages for bash(1). There's a good sized section on history and related topics there.

smehra24 01-29-2008 01:09 AM

Use CTRL+R
 
Use the above combination of the keys to search for a string.. very helpful indeed.

ComputerGreek 01-29-2008 03:14 AM

I see smehra24 has already answered.

Just use EMACS commands.

What you want is

Code:

Ctrl-R wget
Ctrl-R is the usual EMACS reverse search command.

Look in "info bash" for more info.


All times are GMT -5. The time now is 11:44 PM.