我制作了 bash 脚本来自动将浏览器扩展打包到.zip
存档中,但由于某种原因,除了当前目录(public
文件夹manifest.json
和index.html
)中的内容之外,它还打包mcm_extension
文件夹(上层文件夹)以及其中的当前文件夹以及其中的全部内容。因此我的结论是:
mcm_extension/
-{current folder name}/
--public/
--manifest.json
--index.html
public/
manifest.json
index.html
代替
public/
manifest.json
index.html
在mcmc.zip
和mcmf.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
。