Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 tar (websites.tgz) that contain a bunch of Drupal websites that are tarred up starting with 'htdocs'

I need to untar them into


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:


Thanks for any help.

share|improve this question
If you don't have permissions to place the tarfile in /local, then you can't create the subdirectories. Or do they exist already? – vonbrand Feb 11 '13 at 20:29
up vote 5 down vote accepted

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 -)
share|improve this answer

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.