If i'm writing a long command or just typing an extensive file path, is there any that i can "reuse" it with some command shortcut?

e.g:

1.cp /home/myuser/really/big/file/here/and/there.png /home/myuser/really/big/file/here/and/there.png.bkp

Do i really have to type it all over again?

link|improve this question

25% accept rate
feedback

3 Answers

up vote 12 down vote accepted

Use brace expansion

cp /home/myuser/really/big/file/here/and/there.png{,.bkp}
link|improve this answer
1  
I think you've got some extra ` characters in there – blahdiblah Jun 8 '11 at 19:43
Neat!That was exactly what i was looking for! – Fisher Jun 8 '11 at 19:47
1  
+1 and you can go even shorter: cp /home/myuser/really/big/file/here/and/there.{,.bkp} – Mike Fitzpatrick Jun 8 '11 at 22:53
@peth: Oops, yes, you're correct. So we can actually go even shorter: cp /home/myuser/really/big/file/here/and/there{,.bkp} :) – Mike Fitzpatrick Jun 16 '11 at 22:58
feedback

Also, history expansion can work here:

cp /home/myuser/really/big/file/here/and/there.png !#:1.bkp

where the !#:1 part refers to the first argument of the command you're currently typing.

link|improve this answer
feedback

You can save lots of time typing that by using tab expansion, the tilde shortcut, and command history.

For instance,

~/r[tab]/b[tab]/f[tab]/h[tab]/a[tab]/t[tab]/

(where [tab] means "press the Tab key") would expand to

/home/myuser/really/big/file/here/and/there

You could also type

cp /home/myuser/really/big/file/here/and/there.png /some/destination

then press up-arrow and just change the last three letters of the filename

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.