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

27,183
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

Share:
27,183

Related videos on Youtube

Shafiul
Author by

Shafiul

Updated on September 18, 2022

Comments

  • Shafiul
    Shafiul over 1 year

    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?