Reuse Last Argument

Device

  • Terminal

How

  1. In zsh or bash with history expansion enabled, type !$ where you want the previous command's last argument.
  2. Press Return to expand and run; in bash you can often press Tab after !$ to expand in place first.
  3. Example: cd /some/long/path then ls !$ becomes ls /some/long/path

Try this

Run cd ~/Documents, then type ls !$ and press Enter. Notice how it automatically uses the Documents path from your previous command.

Why it works

Chain work without retyping paths.

Open full demonstration ↗