上位フォルダをフォルダの内容とともに圧縮しています

上位フォルダをフォルダの内容とともに圧縮しています

ブラウザ拡張機能をアーカイブにパックするプロセスを自動化する 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.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

関連情報