9

I'm using this command to archive a directory named g from Java code:

tar czf /a/b/c.tar.gz /e/f/g

When the tar file c.tar.gz is created, I find an entire path e/f/g then all files of the g folder inside it. But I only want to see files under the folder g in the compressed archive when I open it. How do I remove the folders /e/f/ in the .tar.gz file?

11
tar -czf /a/b/c.tar.gz -C /e/f/g .

The -C option makes tar change the working directory, so you only need to add ..

See: Changing the Working Directory – GNU tar manual

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.