Wednesday, July 23, 2008

How To Repeat Previous Command Line Argument With KeyStroke

With hundreds of linux terminal command lines being saved to shell history file, a good practice of repeating old and previous command line command and argument is another convenience we could make use of.

By realizing a mistake from a recently issued linux command like

# vi /usr/share/wordpress/wp-content/themes/vertito/images/imgs/

could be tiresome specially if the linux command parameter is longer 50 characters.

One approach to tackle this scenario is by simply hitting the ketboard's Up Arrow Key to repeat the previously issued linux command. This Up Arrow keystoke, when pressed inside a shell environment, repeats the previously issued command taken from the keystroke command buffer ring. The problem with using this shortcut keystroke is that it cycles back to previously issued wrong linux command or command with wrong parameter. Tendency is you hit more keystroke combinations to edit the command, say Control + A to begin editing the first few letters of the command or Control + E to modify the last portion of the command.

If you want to repeat the recently issued command line parameter from the previously issued command, you can use this approach.

Say, to list down directory contents of a folder, we issue the below command by mistake

# vi /usr/share/wordpress/wp-content/themes/vertito/images/imgs/

But our intention is to list down the files and directory on that folder. This basically means we need to retype the parameter, or do the Up Arrow key to repeat the previously issued command. Here's another alternative to accomplish the same task.

# ls -la !*

!* combination repeats the last supplied command with the previous command.

All is done

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy