Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

Essentially:

[ username ubuntu ~ ] $ becomes

[ username ubuntu ~ ] 286 $

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

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

2 Answers 2

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

 
discard

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.