Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Navigate on Linux command shell history

Date: 2009-01-06 00:00:00 -0400

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.

 <dl>

!
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.

string1string2
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

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.