! is a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (
PS1="\!$ ") so you can quickly look at your screen to get numbers for past commands.
Now that you can use arrow keys and things like Ctrl-R to search the command history, I don't see much use for the feature.
One variant of it you might still find useful is
!!, which re-executes the previous command. On its own, I don't find !!Enter any faster than just ↑ Enter, but it can be helpful when combined into a larger command.
Example: A common pilot error on
sudo based systems is to forget the
sudo prefix on a command that requires extra privileges. A novice retypes the whole command. The diligent student edits the command from the shell's command history. The enlightened one types
Bash lets you disable
! processing in the shell with
set +o histexpand or
set +H. You can disable it in Zsh with