7

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..?

2
  • 7
    You should answer your own question and accept that answer. That's usually how it's done on SE sites.
    – user13742
    Commented Mar 3, 2013 at 18:40
  • 1
    I see you found \! below; also, check out \#. Commented Mar 6, 2013 at 1:18

2 Answers 2

10

\! is the history number. Source.

2
  • Upvoted for answering the question without editorializing.
    – vwvan
    Commented Jan 30, 2019 at 22:54
  • In zsh it's %!. Commented Dec 1, 2019 at 21:06
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .