我正在将上层文件夹与文件夹内容一起压缩

我正在将上层文件夹与文件夹内容一起压缩

我制作了 bash 脚本来自动将浏览器扩展打包到.zip存档中,但由于某种原因,除了当前目录(public文件夹manifest.jsonindex.html)中的内容之外,它还打包mcm_extension文件夹(上层文件夹)以及其中的当前文件夹以及其中的全部内容。因此我的结论是:

mcm_extension/
-{current folder name}/
--public/
--manifest.json
--index.html
public/
manifest.json
index.html

代替

public/
manifest.json
index.html

mcmc.zipmcmf.zip.这是脚本:

# Removes .DS_Store files from a project
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

# Creates directories of extension if they don't exist already
mkdir -p ../mcm_extension && mkdir -p ../mcm_extension/mcmc && mkdir -p ../mcm_extension/mcmf

# Google Chrome
cp -R /Users/apple/Development/mcm/public/ /Users/apple/Development/mcm_extension/mcmc/public/
cp /Users/apple/Development/mcm/manifest.json /Users/apple/Development/mcm_extension/mcmc/manifest.json
cp /Users/apple/Development/mcm/index.html /Users/apple/Development/mcm_extension/mcmc/index.html
cd /Users/apple/Development/mcm_extension/mcmc/
zip -r /Users/apple/Development/mcm_extension/mcmc.zip *

# Mozilla Firefox
cp -R /Users/apple/Development/mcm/public/ /Users/apple/Development/mcm_extension/mcmf/public/
cp /Users/apple/Development/mcm/manifestff.json /Users/apple/Development/mcm_extension/mcmf/manifest.json
cp /Users/apple/Development/mcm/index.html /Users/apple/Development/mcm_extension/mcmf/index.html
cd /Users/apple/Development/mcm_extension/mcmf/
zip -r /Users/apple/Development/mcm_extension/mcmf.zip *

答案1

.当前目录和父目录分别由和引用..

因此,要压缩仅不包括当前目录和父目录的内容,请尝试以下操作

zip -r /path_to_folder/* -x .. -x .

仅排除父目录并保留当前目录尝试

zip -r /path_to_folder/* -x ..

-x选项用于在压缩时排除文件或目录zip

相关内容