Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recall the argument of the previous bash command?

Is there a way in Bash to recall the argument of the previous command?

I usually do vi file.c followed by gcc file.c.

Is there a way in Bash to recall the argument of the previous command?

like image 794
The Coder Avatar asked Jul 30 '10 12:07

The Coder


People also ask

How do I recall a bash command history?

Bash also has a special “recall” mode you can use to search for commands you've previously run, rather than scrolling through them one by one. Ctrl+R: Recall the last command matching the characters you provide. Press this shortcut and start typing to search your bash history for a command.

What command brings back the arguments and options from the previous line?

To reuse the arguments from the previous command line on the current command line, use " !* ".

Which bash shortcut for command copies the last argument of previous command?

Which Bash shortcut or command copies the last argument of previous commands? Pressing Esc+.

How do you view the previous commands which you have already executed?

The simplest way to look through your recent commands is to use the up and down arrow keys on your keyboard to scroll through the previous commands. If you want to reissue a found command simply press the enter key.


2 Answers

You can use $_ or !$ to recall the last argument of the previous command.

Also Alt + . can be used to recall the last argument of any of the previous commands.

like image 85
codaddict Avatar answered Oct 24 '22 22:10

codaddict


If the previous command had two arguments, like this

ls a.txt b.txt 

and you wanted the first one, you could type

!:1 

giving

a.txt 

Or if you wanted both, you could type

!:1-2 

giving

a.txt b.txt 

You can extend this to any number of arguments, eg:

!:10-12 
like image 42
Robert Gowland Avatar answered Oct 24 '22 22:10

Robert Gowland