压缩而不创建父文件夹

Zipping without creating parent folder

我有这样的文件夹结构:

- project:
-- folder 01:
--- file1.cpp
--- file2.cpp
-- folder 02:
--- file1.cpp
--- file2.cpp

我想以我得到(当我解压缩时)这个结构的方式压缩项目文件夹的内容:

- folder 01:
-- file1.cpp
-- file2.cpp
- folder 02:
-- file1.cpp
-- file2.cpp

我现在的问题是,我总是得到一个与我的 zip 文件同名的父文件夹,其中包含文件夹 01 和 02。有没有一种方法可以在不获取该父文件夹的情况下进行压缩?

尝试使用

的相对路径
$ cd project
$ tar -cvf newName.tar.gz  ./*

zip -r foo ./

假设**

./

** 即当前工作目录是您的项目。

-r 用于递归压缩

foo 是您的 zip 文件的名称,即 foo.zip 是您想要的最终压缩产品。