Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

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

2 Answers 2

up vote 2 down vote accepted

Just put the comma on the other side

cp -v original.xml{.backup,}
share|improve this answer
    
Awesome seems obvious now! –  jmathew Aug 14 '13 at 14:29
    
@jmathew Good moment to learn what the brace expansion actually does! –  Bernhard Aug 14 '13 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 '13 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 '13 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)

share|improve this answer
    
Wow thats complicated but definitely cool. I didn't know I could learn so much from 6 characters! –  jmathew Aug 14 '13 at 16:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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