Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

edit: I want to extra member01 and member02 and directory blah/

tarball_1.tar.gz contains directory test/ with 20 files. I want to extract only member test/member01 and test/member02 and directory blah/ and copy them to another "remote_host" using ssh/scp.

Can this be done as a one-liner? I considered using tar, pax, or cpio but I guess I'm not very skilled with these utilities yet.

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted
tar -xzOf file.tar.gz file_you_want_to_extract | ssh user@host 'cat > /path/to/destination_file'
  • -x : Extract
  • -z : Through gzip
  • -f : Take in a file as the input.
  • -O : Extract to stdout

The file_you_want_to_extract is extracted from file.tar.gz to the standard output, piped into ssh, which runs cat on the remote host and writes its standard in to the remote destination_file. Of course, you'll want to ensure you have write permission to your desired destination file on the remote host.

share|improve this answer
    
I was not clear in my original posting :) I need to extract more than one member, plus a directory. –  Felipe Alvarez Aug 30 '11 at 8:55
    
should be tar -xz0f : after f comes archive name –  Felipe Alvarez Aug 30 '11 at 8:56
1  
Extracting multiple members will get messy if you want them to be one-liners, since extracting multiple files to stdout doesn't quite make sense. You'll probably have to tar for each one you want to extract, then use scp -r member1 member2 blah user@host:/destination/folder/ to copy them. If you really want to make it one-line, you can concatenate all those commands with &&. A more practical option is to just make a script as well that iterates through the command-line options and executes tar for each one and then scps all of them at the end. –  atanamir Aug 30 '11 at 9:18
    
ahhhhh, I see. So there is no "easy" one-liner method. Thanks :-) –  Felipe Alvarez Aug 30 '11 at 9:27
add comment

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.