Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am a noob in bash to be honest. I have Googled around and cannot find an answer to this:

history lists previous commands and their number e.g.

$ history
286 clear

I want to be able to see the command number as I type a new command, instead of having to type history


[ username ubuntu ~ ] $ becomes

[ username ubuntu ~ ] 286 $

Does anyone know how to achieve this in .bashrc, .bash_profile, .profile etc..?

share|improve this question
You should answer your own question and accept that answer. That's usually how it's done on SE sites. – user13742 Mar 3 '13 at 18:40
I see you found \! below; also, check out \#. – Emanuel Berg Mar 6 '13 at 1:18
up vote 3 down vote accepted

\! is the history number. Source.

share|improve this answer

As an heads-up, you could consider to use [Ctrl+r] shortcut to search backward all occurrences of the search-pattern in the history.

I found it more easy and faster to use. Indeed typing ! and the following number that can be more than 3digits was a bit hampering at times.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.