Enter your email address:

Delivered by FeedBurner

Navigate on Linux command shell history

history is a very useful command in Linux, because it helps you remember the commands you have used in the past.

Well, the way most of people use it, is by typing

history

In the shell, and then copying the command to use it again, but there are some other ways, CTRL+R is another one, but there is also another one, and is to navigate in the list of history commands, using the index it has.

Here is how to do it.

!
Start a history substitution, except when followed by a space, tab, the end of the line, ‘=’ or ‘(’ (when the extglob shell option is enabled using the shopt builtin).
!n
Refer to command line n.
!-n
Refer to the command n lines back.
!!
Refer to the previous command. This is a synonym for ‘!-1’
!string
Refer to the most recent command starting with string.
!?string[?]
Refer to the most recent command containing string. The trailing
‘?’ may be omitted if the string is followed immediately by
a newline.
^string1^string2^
Quick Substitution. Repeat the last command, replacing string1
with string2. Equivalent to !!:s/string1/string2/
!#
The entire command line typed so far.

As you can see, there are lots of options to use history, so learn to get the most of it, you will enjoy it.

Thanks to gnu.org

Share/Save
 #

Great, as always with these tips.

Unfortunately, my version of xubu (8.04) tells me it doesn't know any HISTORY command. I've got fish installed and running and, after typing history, it stays red so I KNOW it's not a command my terminal is familiar with.

sudo apt-get install history reveals no known package 'history'

Help?

 

If this was useful for you, please consider making a donation, any amount is welcome, please proceed by clicking on the yellow donate button, thank you in advance.

Navigation

Recent comments