Unix Reference

Using ! and ctrl-R (goes back through your history to get previous commands)

Video

There are two easy ways to retrieve past commands from your history (in addition to using the up/down arrow keys):

!character: if you type an exclamation point (also known as bang) followed by a character or a string and then enter, you will run the last command that starts with that character or string. E.g.,

$ ls -a
.  ..  hello  hello.c  hello.c~  innerFolder  readme.txt  samples
$ cd ..
$ !l
ls -a
.   assign0  assign2  .do_not_look.txt  file2.txt
..  assign1  assign3  file1.txt     .this_is_hidden.txt
$

Typing !l runs ls -a again, because the previous command that started with l was ls -a.

Ctrl-R: If you hold down the control key, and then type "r", you can then start typing characters and the line will start being populated with the last command that starts with the characters you have typed. This is easier to see in the Video and you should try it yourself.

Back to contents