嘿伙计们我正在尝试将所有文件从一个目录移动到另一个未包含在黑名单中的目录,我收到的错误missing destination file after operand after $SVN
也包含了一些调试器信息,谢谢。< / p>
#!/bin/bash
clear; set -x
# here
ROOT=`pwd`
# dirs
SVN_FOLDER="${ROOT}/svn"
GIT_FOLDER="${ROOT}/git"
# blacklist
EXCLUDE=('.git' '.idea')
EXCLUDELIST=$(printf "|%s" "${EXCLUDE[@]}")
EXCLUDEDIR=`echo "${GIT_FOLDER}/!(${EXCLUDELIST:1})"`
shopt -s dotglob nullglob # see hidden
mv $EXCLUDEDIR $SVN_FOLDER
# + mv {dir}/svn <--- the excluded stuff is NOT in the MV cmd?
# mv: missing destination file operand after ‘{dir}/svn’
答案 0 :(得分:2)
我会这样解决:
#!/bin/bash
SVN_FOLDER="${ROOT}/svn"
GIT_FOLDER="${ROOT}/git"
EXCLUDE=('.git' '.idea')
EXCLUDE_PATTERN=$(IFS='|'; echo "${EXCLUDE[*]}")
EXCLUDE_PATTERN=${EXCLUDE_PATTERN//./\\.}
find "$GIT_FOLDER" -mindepth 1 -maxdepth 1 -regextype posix-egrep -not -regex ".*/(${EXCLUDE_PATTERN})$" -exec mv -i -t "$SVN_FOLDER" '{}' '+'
如果该命令已经适用,您可以选择从-i
命令中删除mv
选项。
答案 1 :(得分:1)
我知道它“效率低下”,但除非你经常移动大量文件,否则简单和权宜之计有什么问题:
blacklist=/tmp/black.lst
srcdir=foo
dstdir=bar
for f in $srcdir/*; do
if !fgrep -qs "$f" $blacklist; then
mv $f $dstdir
fi
done
或者,这个怎么样。我敢打赌,通过硬连接而不是复制内容,它会以速度方式击败其他任何东西:
#!/bin/bash
root=$(pwd)
svn_dir=$root/svn
git_dir=$root/git
blacklist='.git .idea'
exclude='--exclude .svn'
for f in $blacklist; do
exclude="$exclude --exclude $f"
done
if ! [ -e $svn_dir ]; then
cp -al $git_dir $svn_dir
for f in $blacklist; do
rm -rf $svn_dir/$f
done
fi
rsync -a $exclude $git_dir/ $svn_dir
答案 2 :(得分:0)
怎么样找?
find . -maxdepth 1 ! -name '.git' ! -name '.idea' -exec mv {} $DEST \;