20

I often find myself copy-pasting long path in order to create a copy of a file

cp /path/to/file/file1 /path/to/file/file1.bkp

Is there an alternative utility that will NOT require me to type the path/to/file twice? Something like -

nameOfExecutible /path/to/file/file1 'bkp'

Note: I don't want to do a cd to file1s parent directory.

1
  • How is this Question about copying files (with cp being the solution) a duplicate of a Question about using path within mv command? I suggest this valuable Question be re-opened. Jul 23, 2019 at 21:50

1 Answer 1

36

Yes,

cp /path/to/file/file1{,.kbp}

That will get expanded automatically to cp /path/to/file/file1 /path/to/file/file1.kbp

3
  • 1
    Thanks. That saves so much time! Is there a terminology for those brackets?
    – user13107
    Mar 5, 2013 at 3:10
  • 8
    The bash shell is expanding the expression in the curly braces prior to exec'ing cp. You can find it covered in the bash manual, or google for "bash brace expansion"
    – Tim B
    Mar 5, 2013 at 3:21
  • bash brace expansion url Sep 14, 2021 at 8:27

Not the answer you're looking for? Browse other questions tagged .