So I know about using braces when backing up a file to making this sweet and easy like so:

cp -v original.xml{,.backup}

But if I wanted to restore the original I would have to do this

cp -v original.xml.backup original.xml

Is there a neat way to shorten this in a way similar to how brace expansion shortened the first command?

  • 2
    it can get even shorter cp -v original.xml{*,} but then this will work for one file only. Just an idea! Aug 14, 2013 at 14:32
  • @val0x00ff That's a nifty way to truncate as well I'll keep it in mind!
    – jmathew
    Aug 14, 2013 at 14:38

2 Answers 2


Just put the comma on the other side

cp -v original.xml{.backup,}
  • Awesome seems obvious now!
    – jmathew
    Aug 14, 2013 at 14:29
  • @jmathew Good moment to learn what the brace expansion actually does!
    – Bernhard
    Aug 14, 2013 at 15:15
  • @Bernhard Ha yea I should. Like a lot of unix concepts brace expansion is one of those things which I've only ever learned just enough of to get by.
    – jmathew
    Aug 14, 2013 at 15:25
  • @jmathew Keeping up with new questions on this site and reading old, top voted question, should get you going quite a lot :)
    – Bernhard
    Aug 14, 2013 at 16:29

Alternatively, with tcsh, bash or zsh:

cp -v original.xml.backup !#:$:r
  • !: history expansion
  • #: current command line
  • :$: last word
  • :r: get the rest (that is, without the extension)

(yes, I know, too long, twisting fingers too much)

  • Wow thats complicated but definitely cool. I didn't know I could learn so much from 6 characters!
    – jmathew
    Aug 14, 2013 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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