2

Could someone explain to me what !d command does?

It seems to recall an old command (du -sh for me) but I have no idea how this command is chosen.

ppr
  • 1,907
  • 7
  • 23
  • 40

2 Answers2

8

! is event designator in bash. You can read more about it here https://alexbaranowski.github.io/bash-bushido-book/#event-designator-word-designator-modifiers (this is my own book about bash and tricks).

!STRING will invoke the last command starting with STRING.

Edit: Excerpt from the link/book:

To invoke the last command that starts with a given string, use the event designator with a string so that the command looks like !<string>. Example below:

[Alex@SpaceShip cat1]$ whoami
Alex
[Alex@SpaceShip cat1]$ who
Alex :0 2018-04-20 09:37 (:0)
...
[Alex@SpaceShip cat1]$ !who
who
Alex :0 2018-04-20 09:37 (:0)
...
[Alex@SpaceShip cat1]$ !whoa
whoami
Alex
  • 1
    There was comment that I should copy information from the link. It is reasonable, because well it might (I won't delete repo) change in the future. So I edited post. – Alex Baranowski Jan 18 '21 at 12:28
7

According to the manual 9.3.1 Event Designators:

!string
Refer to the most recent command preceding the current position in the history list starting with string.