Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run the following command:

tar cfvz backup.tar.gz /path/to/my/files/*

It gzips the entire path. So when I unzip the file, I have to go open 4 folders (path -> to -> my -> files) to get to the files I wanted to backup.

How do I make the files show in root of the gzipped file rather then the entire path?

Thanks in advance!

share|improve this question
3  
Have you tried: cd /path/to/my/files and then tar czvf backup.tgz * –  cfreire May 27 '13 at 12:25
3  
The --strip-components option while un-taring would also help. Other than that, tar doesn't offer you much… cd ing to the path you want to backup would be the only quick solution that comes to mind. –  slhck May 27 '13 at 12:26
    
@cfreire @slhck Can't believe I didn't think of cd....Thanks so much! –  Ben Sinclair May 27 '13 at 13:13
    
@cfreire, slhck would one of you post that as an answer? –  terdon May 27 '13 at 13:16
add comment

2 Answers

up vote 3 down vote accepted

Try option -C:

tar cvzf backup.tar.gz -C /path/to/my/files/ .

share|improve this answer
add comment

I'm assuming this is in a script so try something like...

pushd /path/to/my/files
tar cfvz backup.tar.gz *
popd

Tar will only include the path specified on the command-line.

share|improve this answer
add comment

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.