Did you know?
!$ reuses the last argument of your previous command.
Or press Alt+. to insert it, so you can see it before running.
- Shell & terminal
- Last checked
Explained
Many commands work on the same path as the one before: create a directory, then enter it; edit a file, then check its permissions. In Bash and Zsh, !$ expands to the last argument of the previous command:
mkdir -p /var/www/example.com/publiccd !$
The second command becomes cd /var/www/example.com/public.
There is an even better way. Press Alt+. (or Esc then .) and the shell inserts the last argument right on the command line, where you can see and edit it before pressing Enter. Press it again to cycle through the last arguments of older commands.
Related history shortcuts: !* is all arguments of the previous command, !^ is the first one, and !! is the entire previous command.
