Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 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
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

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

Your Answer


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.