Linux Training Academy

Helping you level-up your career.

  • About
  • Products
  • Books
  • Linux for Beginners
  • Resources
  • Video Training Courses

Reuse the Arguments from the Previous Command Line

Share
Facebook0
Google+0
LinkedIn0
Twitter0
Pinterest0

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

Related posts:

  • Vim Cheat Sheet
  • Linux Commands Cheat Sheet
  • Want to Quickly Recall the Last Word or Last Argument from the Previous Command Line? Here’s How.
  • Determine Your Private and Public IP Addresses from the Command Line

Filed Under: blog Tagged With: CentOS, Command Line, Linux, Ubuntu, Video

Most Popular

  • Linux Commands Cheat Sheet
  • Linux ip Command Networking Cheat Sheet
  • Vim Cheat Sheet
  • Linux System Administrator Projects
  • 1,500 Coding Project Ideas

Recent Linux Articles

  • Which Distro Should I Choose?
  • Linux Logical Volume Manager Tutorial
  • How to Find Any File or Command on a Linux System
  • Linux tar Command Tutorial
  • How to Prepare for (and Ace) Your Next Technical Interview

Topics

Arch Linux careers CentOS cheat sheet Cloud Command Line Debian Desktop Fedora File System FTP Gentoo Installation jobs Linux Linux Mint Mageia MySQL Nginx OpenSuse Programming Python RedHat SCP Server Shell Scripting Slackware SSH text editor Ubuntu Vagrant Video vim VirtualBox Web Hosting Windows
Linux Cheat Sheet Download
Enter your email address below to download this Linux command line cheat sheet in an easy-to-read and ready-to-print format.

© 2018 · Linux Training Academy

  • Privacy Policy
✕
Free Linux Command Line Cheat Sheet ->