找到wonderful little bash script我adapted用于压缩托管目录的zip,忽略bower_components
,.git
和{node_modules
等文件{1}}:
#!/bin/bash
# This script zips a directory, excluding specified files, types and subdirectories.
# while zipping the directory it excludes hidden directories and certain file types
[[ "`/usr/bin/tty`" == "not a tty" ]] && . ~/.bash_profile
DIRECTORY=$(cd `dirname $0` && pwd)
if [[ -z $1 ]]; then
echo "Usage: managed_directory_compressor /your-directory/ zip-file-name"
else
DIRECTORY_TO_COMPRESS=$1
ZIPPED_FILE="$2.zip"
COMPRESS_IGNORE_DIR=("\.git" "node_modules" "bower_components")
IGNORE_LIST=("*/\.*" "\.* "\/\.*"")
if [[ -n $COMPRESS_IGNORE_DIR ]]; then
for IGNORE_DIR in "${COMPRESS_IGNORE_DIR[@]}"; do
IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/***") ## "$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/*" perhaps is enough?
done
fi
zip -r "$ZIPPED_FILE" "$DIRECTORY_TO_COMPRESS" -x "${IGNORE_LIST[@]}" # >/dev/null
echo zip -r "$ZIPPED_FILE" "$DIRECTORY_TO_COMPRESS" -x "${IGNORE_LIST[@]}" # >/dev/null
echo "Done"
fi
唯一的问题是我想要忽略的目录仍在创建,只是空。
有什么建议吗?
答案 0 :(得分:1)
zip-man-page说
请注意,目前目录需要尾随/(如
)zip -r foo . -i dir/
包含目录dir。)
因此,同样的排除似乎也有效:用
替换脚本中的标记行IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/")
应该这样做。
(我的zip是Ubuntu-Linux上的3.0版本)