# Fixing Mistakes


Hi everyone, Brian here to talk about how to quickly fix mistakes when you typed out a command.

It happens, You make a typo and don't realize it until after you typed the command.

One of the most common places this happens is when you're trying to do something with `sudo` and you forgot to use `sudo`.

```command
mkdir /var/test_dir
```

That command fails. 

```
mkdir: cannot create directory ‘/var/test_dir’: Permission denied
```

If you type two exclamation points, `!!`, it'll run your previous command again. 

```command
!!
```

```
mkdir /var/test_dir
mkdir: cannot create directory ‘/var/test_dir’: Permission denied
```


But if you type 

```command
sudo !!
```

```
sudo mkdir /var/test_dir
```

it runs your previous command again with `sudo`. Not ashamed to admit I use this one all the time.

Sometimes you might just be typing too fast and you'll make a typo in the command:

```command
mdkir test_dir
```

```
mdkir: command not found
```

The command is supposed to be `mkdir`. I can fix that with a little bit of substitution:

```command
^mdk^mkd
```

```
mkdir test_dir
```

Hurray! It's fixed! The new command prints and executes.

There you go! A couple of quick ways to fix mistakes when typing. 

These approaches leverage a feature called history expansion, which you can learn more about in the book.

Thanks for watching!

