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.

0

2 Answers 2

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
  • 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. Jan 18, 2021 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.

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