Arman Arman - 1 year ago 184
Linux Question

Create tar.gz archive and add all files and folders without parent folder

For example i have folder "admin" which contains folder "1" and two php files "index.php" and "page.php". I try to use

tar -zcvf admin.tar.gz admin
and got admin.tar.gz archive. If i open this archive, i can see archive contains "admin" folder and inside this directory is folder "1" and two php files.

I want to create tar.gz archive with all files and folders, but without parent folder. Create archive and it contains only folder "1" and two php files. How i can do it?

Answer Source

You can use the -C option:

tar -C admin -zcvf admin.tar.gz .

See man tar

-C, --directory=DIR
   Change to DIR before performing any operations.
   This option is order-sensitive, i.e. it affects all options that follow.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download