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/ /path/to/somewhere/directory/
$ cp !$ /home/you

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

1 comment… add one
  • Zoffix Znet Sep 27, 2013 @ 15:02

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.