Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

When trying to package .tar.gz files from folders (backup) using this script

tar -zcvf desktop.tar.gz /home/USER/Desktop/

It's suppose to be saved as 'desktop.tar.gz' and its a copy of '/home/USER/Desktop/', but inside the .tar.gz the file structure is /home/USER/Desktop/ instead of just Desktop/. Any ideas on how to make it save as just Desktop/ ?

share|improve this question
up vote 2 down vote accepted

Use the -C option with tar like this:

$ tar -zcvf desktop.tar.gz -C /home/USER Desktop/

This will change the working directory of tar to /home/USER while running, effectively stripping out the /home/USER prefix of the paths.

share|improve this answer
Worked perfectly! Thank You! – seanthewebber Nov 15 '12 at 22:04

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.