Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH: reuse argument from same command

Tags:

bash

I know I can reuse the first argument from the prævious command with !:1; but is it possible to reuse an already typed argument from the command currently being entered? Say I want to cp blablabla blablabla.bak (and assume there are other similarly named files in the directory); it would be nice not to have to type blablabla all over again.

like image 654
Toothrot Avatar asked Feb 09 '23 22:02

Toothrot


1 Answers

Yes; you can use the history expansion !# to represent the current line so far:

cp blablabla !#:1.bak
like image 84
chepner Avatar answered Feb 20 '23 18:02

chepner