Sunday, March 30, 2008

Shell: Shortcut To Last Command Line Argument

Have you noticed at times that you have been entering same command line parameter over and over again during a certain portion of your shell works?
Have you ever been tired of entering the last command line argument over and over again?

Here's a quick and simple short tip on how to execute shortcut combination keys to make that long-typing parameter words easy to shell redo again.

If you were trying CD into a particular folder like

# cd /home/www/cpanel/com/level2/shared/customers/public_html
bash: cd: /home/www/cpanel/com/level2/shared/customers/public_html: No such file or directory

Now, enter the combination short cut keys for entering the last parameter like so

# mkdir !*
# cd !*
# ls -la !*

The above '!*' would be substituted by /home/www/cpanel/com/level2/shared/customers/public_html when executed by bash.

1 comments:

Anonymous said...

Just a precision: !* is for the last list of arguments; !$ is for the last argument alone:

$ echo a b c
a b c
$ echo !*
echo a b c
a b c
$ echo d e f
d e f
$ echo !$
echo f
f

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy