Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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

 
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.