What does “cd !$” mean in bash, and what other substitutions like these can I use

bashshell

I've seen somebody do:

cp . yy/
cd !$

the last line translated to:

cd yy/

so I think !$ means "the last argument from previous line".

Am I right?

Are there any other substitution of this kind?

Where can I find the documentation for them?

Best Answer

!$ is the last word of the last command.

More:

!! - Last command
!foo - Run most recent command starting with foo (ex. !ps, !mysqladmin)
!foo:p - Print command that !foo would run, and add it as the latest to command history
!$ - Last 'word' of last command (/path/to/file in the command ls -lAFh /path/to/file, -uroot in mysql -uroot)
!$:p - Print word that !$ would substitute
!* - All but first word of last command (-lAFh /path/to/file in the command ls -lAFh /path/to/file, -uroot in mysql -uroot)
!*:p - Print words that !* would substitute

^foo^bar - Replace foo in last command with bar, print the result, then run. (mysqladmni -uroot, run ^ni^in, results in mysqladmin -uroot)

{a,b,c} passes words to the command, substituting a, b, and c sequentially (cp file{,.bk} runs cp file file.bk)

Ctrl + a - Jump to the start of the line
Ctrl + b - Move back a char
Ctrl + c - Terminate the command
Ctrl + d - Delete from under the cursor
Ctrl + e - Jump to the end of the line
Ctrl + f - Move forward a char
Ctrl + k - Delete to EOL
Ctrl + l - Clear the screen
Ctrl + r - Search the history backwards
Ctrl + R - Search the history backwards with multi occurrence
Ctrl + t - Transpose the current char with the previous
Ctrl + u - Delete backward from cursor
Ctrl + w - Delete backward a word
Ctrl + xx - Move between EOL and current cursor position
Ctrl + x @ - Show possible hostname completions
Ctrl + z - Suspend/ Stop the command
Ctrl + x; Ctrl + e - Edit line into your favorite editor

Alt + < - Move to the first line in the history
Alt + > - Move to the last line in the history
Alt + ? - Show current completion list
Alt + * - Insert all possible completions
Alt + / - Attempt to complete filename
Alt + . - Yank last argument to previous command
Alt + b - Move backward
Alt + c - Capitalize the word
Alt + d - Delete word
Alt + f - Move forward
Alt + l - Make word lowercase
Alt + n - Search the history forwards non-incremental
Alt + p - Search the history backwards non-incremental
Alt + r - Recall command
Alt + t - Transpose the current word with the previous
Alt + u - Make word uppercase
Alt + back-space - Delete backward from cursor

From http://cheat.errtheblog.com/s/bash/.

Also, lots of good stuff here: http://www.gnu.org/software/bash/manual/bashref.html
and here: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html.