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.

I have a file "elasticsearch-servicewrapper.tar.gz". When I try to run:

tar -xvf elasticsearch-servicewrapper.tar.gz

I expect the extracted folder to be called "elasticsearch-elasticsearch-servicewrapper". But instead, I got "elasticsearch-elasticsearch-servicewrapper-d47d048". Is there a way I can force the target folder name?

This is on Ubuntu 12.04.

share|improve this question

migrated from stackoverflow.com Nov 9 '12 at 18:16

This question came from our site for professional and enthusiast programmers.

    
tar extracts files to the directory it finds itself in, with the filenames found in the archive. If the names in the archive start with "elasticsearch-elasticsearch-servicewrapper-d47d048/", then you can't easily prevent tar from creating that directory. Except perhaps symlink it to your desired location before untarring. –  Henning Makholm Nov 9 '12 at 16:40
    
... hmm, actually with GNU tar you can use --strip-components 1 to make it ignore the first pathname element of each archived file name. –  Henning Makholm Nov 9 '12 at 16:42
add comment

2 Answers 2

up vote 5 down vote accepted

It's not up to tar - the directory is only created because it was inside the tarball anyway, so it has whatever name is stored inside the tarball.

You can make your own target folder and extract it into that using --strip-components to take off leading pathnames as a workaround.

share|improve this answer
add comment

Why don't your just rename it by mv elasticsearch-elasticsearch-servicewrapper-d47d048 elasticsearch-elasticsearch-servicewrapper ?

You could try tar -xvf elasticsearch-servicewrapper.tar.gz -C /tmp/elasticsearch-servicewrapper too.

share|improve this answer
    
it's part of the puppet code, so I am trying to do something like:tar -xzf /tmp/elasticsearch-servicewrapper.tar.gz -C /tmp && mv /tmp/elasticsearch-servicewrapper /usr/local/elasticsearch-0.19.11/bin –  Shengjie Nov 9 '12 at 16:39
    
I see. I've updated my answer. See if that works. –  Benjamin Tan Nov 9 '12 at 16:43
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.