Quick Tip: Exploring Your Bash History

Typically when you type a shell command its recorded in the bash history. If you ever needed to see what you typed in the past, a useful tool is the history command. By typing history in the shell it will display a list of commands (commonly the last 500) in the shell.

user@computer:~$ history
1 ls
2 mkdir testdir
3 cd testdir/
4 vi testdoc
5 ls
6 cd ..
7 rm -r testdir/
8 history

One of the benefits of the history command is if there is a command in your history you wish to execute again. You can do so by typing !<history number>.

Using the history list above, typing !2 would execute the command mkdir testdir again.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s