5

I have a tar (websites.tgz) that contain a bunch of Drupal websites that are tarred up starting with 'htdocs'

I need to untar them into

/local/htdocs/web1
/local/htdocs/web2

and so on. But I cannot place the websites.tgz file in /local and extract downward due to permissions. It is currently in my home directory. How can I untar the contents under /local/htdocs, without including the top-level htdocs directory?

I am trying to avoid having:

/local/htdocs/htdocs/web1
/local/htdocs/htdocs/web2.

Thanks for any help.

1
  • If you don't have permissions to place the tarfile in /local, then you can't create the subdirectories. Or do they exist already? Commented Feb 11, 2013 at 20:29

2 Answers 2

5

You can use the -C option in some tar implementations to specify the base path for extraction. The following will work for your example.

tar -xvz -C /local -f websites.tgz

Or if your tar doesn't have the -z or -C options:

gunzip < websites.tgz | (cd /local && tar xvf -)
2

You may want to use the --strip-components=NUMBER option of GNU tar:

--strip-components=NUMBER
  strip NUMBER leading components from file names on extraction

Your command would be:

tar -xfz /path/to/websites.tgz --strip-components=1 -C /local/htdocs/

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.