简体   繁体   English

创建tar.gz存档并添加所有没有父文件夹的文件和文件夹

[英]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". 例如,我有文件夹“ admin”,其中包含文件夹“ 1”和两个php文件“ index.php”和“ page.php”。 I try to use tar -zcvf admin.tar.gz admin and got admin.tar.gz archive. 我尝试使用tar -zcvf admin.tar.gz admin并获得admin.tar.gz存档。 If i open this archive, i can see archive contains "admin" folder and inside this directory is folder "1" and two php files. 如果我打开此存档,我会看到存档包含“ admin”文件夹,并且在此目录内是文件夹“ 1”和两个php文件。

I want to create tar.gz archive with all files and folders, but without parent folder. 我想用所有文件和文件夹创建tar.gz存档,但没有父文件夹。 Create archive and it contains only folder "1" and two php files. 创建存档,它仅包含文件夹“ 1”和两个php文件。 How i can do it? 我该怎么办?

You can use the -C option: 您可以使用-C选项:

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

See man tar 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM