How do I remove the full path when doing a tar.gz compression?

9

1

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?

Shafiul

Posted 2013-12-24T11:06:03.583

Reputation: 208

Answers

13

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

slhck

Posted 2013-12-24T11:06:03.583

Reputation: 182 472