Greg Jones wrote:
--- On Thu, 1/7/10, Don Delp <[email protected]> wrote:
On Thu, Jan 7, 2010 at 9:41 AM, Curt
Lundgren <[email protected]>
wrote:
If you do "!se" you'll execute the most recent command
that starts with the
letters "se". I find I use this more than
re-executing by number.
Curt
On Wed, Jan 6, 2010 at 6:41 PM, Perkins, Jerry <[email protected]>
wrote:
Dave, this is even new to me, so I am also
sending it on to a couple
others.
Reuse your history
After some time learning and experimenting at the
command line, you'll
find that you want to go back and repeat a command
you executed at some
point during the past. Luckily, Unix (and Cygwin)
track every single command
you ever type in a file called .history. Type the
history command to see the
last 100 commands you ran, which will be numbered,
like this:
penel...@scully ~
$ history
....
82 echo gift-ideas.txt
83 grep Mom gift-ideas.txt
84 man grep
85 ls | grep .txt
86 ls
87 ls | grep todo
88 ls | grep .txt
89 ls >>
file-listing.txt
90 cat file-listing.txt
91 history
Now, if you want to redo command number 87, let's
say, you don't have to
retype it. The "bang" (exclamation point) and the
command number will get
the job done. Just type !87 at the prompt, hit
enter, and - in my case - ls
| grep todo - will be re-executed.
Use grep to pick out the command of interest from
your history. For
example, to see all the ls recipes you've used in
the past, grep your
history for ls, like so:
penel...@scully ~
$ history | grep ls
11 ls
13 ls
14 cls
20 ls
21 ls
27 ls
46 man ls
47 ls -l
48 ls
49 man ls
50 ls -lh
51 ls
...
Neat, huh?
I find myself using !! frequently. It calls the most
recent command.
My most common use is after running a command and getting
an error
that only root can do that.
sudo !!
Not only is it easier than (up arrow) (home) sudo, but
visually it
looks like the computer correctly interprets your
exasperation. ;)
I wanted to add to the FYI of neat history tricks. In BASH you can type Ctrl+r to do a search on a command. If you type Ctrl+r and then type ssh it will show the last ssh command you entered. If that isn't the one you want simply hit Ctrl+r again and it will jump to the next one. So on and so on until you find the one you want to use. It goes from newest to oldest. Then just hit enter when you find the command and you are in business.
Another cool aspect of this search is if you want to do a variation on a previous command. Hit Ctrl+r, type and search for the command and once you find the one you want to alter hit Esc. This will drop you to a prompt with that command on the line and you can edit it. This is useful for really long commands.
I love all these different short cuts. Thanks for posting.
Greg
All of those above were new to me. This is great.
My brother-in-law sent me a link that has all of this in detail,
plus.
http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/
--
Jerry Perkins - http://jperkins.us/
Calling an illegal immigrant an undocumented worker
is like calling the corner drug dealer an unlicensed Pharmacist.
|