Git 在Bash脚本中使用ignore压缩
找到一个我必须用于压缩托管目录的压缩包,忽略诸如Git 在Bash脚本中使用ignore压缩,git,bash,zip,Git,Bash,Zip,找到一个我必须用于压缩托管目录的压缩包,忽略诸如bower\u组件、.git和node\u模块等文件: #!/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/t
bower\u组件
、.git
和node\u模块等文件
:
#!/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
唯一的问题是,我想忽略的目录仍在创建中,只是空的
有什么建议吗?zip手册页上说
请注意,当前目录需要尾随/字符(如中所示)
包括目录目录(dir)
因此,类似地,排除似乎也起作用:将脚本中的标记行替换为
IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/")
我们应该做到这一点
(我的zip是Ubuntu Linux上的3.0版)
IGNORE_LIST+=("$DIRECTORY_TO_COMPRESS/$IGNORE_DIR/")