[Bash] Rerun Bash Commands with History Expansions (!! & !$)

!! & !&

History expansions let you interact with bash's history. For example, if you forgot to run a command with sudo, you can sudo !! to rerun the last command with it. !$ can be used to access the last argument of the last command.

Rerun last command

date
## print the date
!!
## print the date again

It is useful when you forgot to add sudo

ifconfig en0 down
## error because of sudo 
sudo !!

Last argument of previous command

touch script.js
## last argument is 'script.js'
chmod +x !$
## the same as chmod +x script.js
原文地址:https://www.cnblogs.com/Answer1215/p/14398089.html