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?
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.
To reuse the arguments from the previous command line on the current command line, use " !* ".
Which Bash shortcut or command copies the last argument of previous commands? Pressing Esc+.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With