BASH shell insert the arguments to a previous command into the current input line

by on June 12, 2007 · 1 comment· LAST UPDATED July 7, 2007

in , ,

Q. I’m using CentOS Linux server. How do I insert the arguments to a previous command into the current input line or fix errors in previous commands quickly?

A. BASH History expansion is useful and time saving feature. To designates the last argument of the preceding command use !$

For example, consider following command:
$ cp /tmp/file.name /path/to/somewhere/directory/file.name
$ cp !$ /home/you

!$ will automatically expand into /path/to/somewhere/directory/file.name, thus calling last command argument. See HISTORY expansion section by typing man bash command for more information:
man bash

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 1 comment… read it below or add one }

1 Zoffix Znet September 27, 2013 at 3:02 pm

Thanks for posting. Read the man page section; tons of various options and modifiers available!

Reply

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: