Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




4.2. The command-line history

Using the command

history Use the up and down key's to scroll through previously typed commands. Press [Enter] to execute them or use the left and right arrow keys to edit the command first. Also see history (below).

The history

command The history command can be used to list Bash's log of the commands you have typed:

This log is called the "history". To access it type:

history n

This will only list the last n commands. Type "history" (without options) to see the the entire history list.

You can also type !n to execute command number n. Use !! to execute the last command you typed.

!-n will execute the command n times before (ie. !-1 is equivalent to !!).

!string will execute the last command starting with that "string" and !?string? will execute the last command containing the word "string". For example:


Will re-run the command that you last typed starting with "cd".

" commandName !*" will execute the "commandName" with any arguments you used on your last command. This maybe useful if you make a spelling mistake, for example. If you typed:

emasc /home/fred/ /tmp/

In an attempt to execute emacs on the above two files this will obviously fail. So what you can do is type:

emacs !*

This will execute emacs with the arguments that you last typed on the command line. In other words this is equivalent to typing:

emacs /home/fred/ /tmp/
Searching through the Command History ( CTRL-R )

Use the CTRL-R key to perform a "reverse-i-search". For example, if you wanted to use the command you used the last time you used snort, you would type:

CTRL-R then type "snort".

What you will see in the console window is:


After you have typed what you are looking for, use the CTRL-R key combination to scroll backward through the history.

Use CTRL-R repeatedly to find every reference to the string you've entered. Once you've found the command you're looking for, use [Enter] to execute it.

Alternatively, using the right or left arrow keys will place the command on an actual command line so you can edit it.

  Published under the terms of the GNU General Public License Design by Interspire