Linux bash use arguments of previous command

In previous post we seen about reusing command line history.

Now I will explain about how to reuse previous command arguments.

With following command I am listing directory a b c d e

$ ls a b c d e

!$ is to use last argument of previous command.

Example:

$ ls !$

Above command will list directory e.

!:1 is to use first argument of previous command.

Example:

$ ls !:1

Above command will list directory a.

!:2 is to use second argument of previous command.

Example:

$ ls !:2

Above command will list directory b.

Similarly we can get other arguments.

We can generalize this as !:n where n is argument position and n start from 1 to and so on…

-Sany

One comment on “Linux bash use arguments of previous command

  1. Pingback: from Sany’s Linux Blog « meditationatae

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s