> ## Content Index
> Fetch the complete content index at: https://mfitzp.ghost.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Re-execute command line with !
- URL: https://mfitzp.ghost.io/re-execute-command-line-with/
- Published: 2011-10-22T00:00:00.000Z
- Updated: 2026-09-09T09:15:57.000Z
- Description: Bash history expansion allows you to quickly re-run previous commands using ! and the number of the command in your history.
- Author: Martin Fitzpatrick
- Tags: Tutorials, Bash, #Import 2024-03-14 08:20, #Import 2026-08-24 14:26

Bash keeps a history of all commands executed in the shell and this can be referenced using the `!` command. Typing two !'s at the prompt will execute the previous command:

```Bash
$ echo "HELLO"
HELLO
$ !!
echo "HELLO"
HELLO

```

The history of the bash shell can be accessed by entering `history`

```Bash
501  echo "HELLO"
502  echo "HELLO"
503  history

```

Notice that each entry has an associated number which can be used to refer to the command.

Entering `!` followed by a line number from the history will run that command

```Bash
$ !501
echo "HELLO"
HELLO

```

You can also search the history by using a search string to match the command instead of a number

```Bash
$ !echo
echo "HELLO"
HELLO
```