bash

TIL: Bash History CLI Shortcuts

## Previous Command's All Arguments
mkdir long_path_here/new_dir
cd !*

## Previous Command's Last Argument
mkdir long_path_here/new_dir
cd !$

or even use $_ instead of !$

## Previous Command's First Argument
mkdir long_path_here/new_dir
cd !^
## History
mkdir long_path_here/new_dir
cd `Esc` `.`
cd `Alt`+`.`

Pressing Esc followed by . will give previous arguments

## "More Options"

!^      first argument
!$      last argument
!*      all arguments
!:2     second argument

!:2-3   second to third arguments
!:2-$   second to last arguments
!:2*    second to last arguments
!:2-    second to next to last arguments

Getting Alt to run on iTerm

  • Open Preferences in iTerm using Command+,
  • Go to Profiles
  • Go to Keys
  • Fix the setting Left option key acts as

    iTerm Preferences - How to Change Alt as Meta key

If you are Terminal on Mac, consider moving to iTerm(if you are not a power user)

  • If you still want this setting in Terminal, look here

Sources