Reuse the Arguments from the Previous Command Line

To reuse the arguments from the previous command line on the current command line, use “!*“. The arguments are considered anything on the command line, except for the first item. Since the first item is almost always a command, then everything following is an argument.

Using this shortcut can be helpful in a couple of different situations. First, it’s great when you are working on a list or series of items, such as files or directories. It also proves to be useful when you accidentally mistype a command. Instead of typing the entire command line over again, simply correct your typing mistake and follow it with “!*“.

The following is an example of working with a series of items.

$ ls file1 file2 file3
file1 file2 file3
$ vi !*
$ mv !* /tmp/

Yet another example dealing with a list of items. In this case, directories.

$ mkdir one two three
$ chmod 700 !*
$ ls -l
drwx------ 2 jason users 4096 Jul 5 18:44 one
drwx------ 2 jason users 4096 Jul 5 18:44 three
drwx------ 2 jason users 4096 Jul 5 18:44 two

Here are examples of correcting command typos.

$ grpe -i error /var/log/syslog
grpe: command not found
$ grep !*
Jul 5 23:47:25 linuxsvr dbus[786]: [system] Error activating service 'org.freedesktop.Accounts'
$ sud apt-get install docker.io
sud: command not found
$ sudo !*
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
aufs-tools
Suggested packages:
btrfs-tools lxc rinse
The following NEW packages will be installed:
aufs-tools docker.io
0 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.
Need to get 3,818 kB of archives.
After this operation, 22.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Fetched 3,818 kB in 37s (103 kB/s)
Selecting previously unselected package aufs-tools.
(Reading database ... 241571 files and directories currently installed.)
Preparing to unpack .../aufs-tools_1%3a3.2+20130722-1.1_amd64.deb ...
Unpacking aufs-tools (1:3.2+20130722-1.1) ...
Selecting previously unselected package docker.io.
Preparing to unpack .../docker.io_0.9.1~dfsg1-2_amd64.deb ...
Unpacking docker.io (0.9.1~dfsg1-2) ...
Processing triggers for man-db (2.6.7.1-1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up aufs-tools (1:3.2+20130722-1.1) ...
Setting up docker.io (0.9.1~dfsg1-2) ...
Adding group `docker' (GID 132) ...
Done.
docker.io start/running, process 4110
Processing triggers for libc-bin (2.19-0ubuntu6) ...
Processing triggers for ureadahead (0.100.0-16) ...
$
Argument