≡ Menu

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

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

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 1 comment… add one }
  • Zoffix Znet September 27, 2013, 3:02 pm

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

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , ,