Bash command arguments
If you use Bash at the command-line you have probably found a need for some shortcut keys. If you have a long command like:
ls -lsa --sort time /some/long/path/to/file.txt
Often in a follow up command you will want to reference the previous command's arguments. In this example if you want to reference the file from the previous command you either have to type it all out again, copy and paste the previous argument, or use a Bash shortcut.
| Shortcut | Description |
|---|---|
!! |
entire previous command |
!$ |
last argument of previous command |
!^ |
first argument of previous command |
!:2 |
second argument |
!:1-3 |
arguments 1 through 3 |
!* |
all arguments |
You could use the !$ shortcut to reference the last parameter from the previous command
vim !$
This is a lot less typing, and quicker. The ^ and $ also line up nicely with the logic from regular expressions: first and last. Another real world example that I run into is creating a directory and then changing into it:
mkdir /var/tmp/user/path
cd !$
Tags:



