Retrieve Back Command Been Enter

August 31st, 2006 liewsheng Posted in alias, history | Hits: 22804 | 1 Comment »

Everytime you enter a command in shell. It will be store it a file for later use, so you can retrieve back the command later. History is use to show all the pass command you have enter in the shell, but history only shown a limited number which have been set in a configuration file:

history

the output will be something like this:

494  vim /var/log/faillog
495  cd ..
496  ls
497  htop
498  top
499  htop
500  uname

You may wonder how you can re-enter back the command listed above, actually it is simple. For example if you want to enter back the command number 496, you can just enter:

!496

the ‘ls’ command will be used. How about the previous command which start with ‘vim’, you can simply enter

!vim

and so following command will be used

vim /var/log/faillog

or you can using

history | grep vim

and the output will be

vim /var/log/faillog

so usually I add these to my aliases file:

alias hg='history | grep'

next time i just using

hg vim

to search for the command which have the ‘vim’ word.

One Response to “Retrieve Back Command Been Enter”

  1. [...] mess up my servers! Your actions will be track! Related PostsRetrieve Back Command Been Enter Everytime you enter a command in shell. It will be store it a file for later use, so you can [...]

Leave a Reply