回答:
このextended_globオプションは、zsh独自の拡張glob構文を提供します。
setopt extended_glob
rm -- ^*.dmg
rm -- ^*.(dmg|txt)
ksh_globオプションを設定してksh globを取得できます。ネガティブパターンが単語の最後のものである一般的なケースでは、zshはかっこをglob修飾子として解析する場合があることに注意してください(kshエミュレーションモードではこれを行いません)。
setopt ksh_glob
rm -- !(*.dmg|*.txt)
setopt no_bare_glob_qual
rm -- !(*.dmg)
ksh_globオプションを設定しなかったことを示します。「イベントが見つかりません:ディレクトリ」は、bashを実行していることを示します(これも!(…)構文を理解しますが、後にのみshopt -s extglob)。
setopt ksh_glob; echo !(a|b)動作setopt ksh_glob; echo !(a)しない間(「期待される数」)...
findシェルの代わりに使用できます:
find . -mindepth 1 -maxdepth 1 ! -name "*.dmg" -delete
からman find:
! expr True if expr is false. This character will also usually need
protection from interpretation by the shell.
-name pattern
Base of file name (the path with the leading directories removed)
matches shell pattern pattern.
-delete
Delete files; true if removal succeeded. If the removal failed,
an error message is issued. If -delete fails, find's exit status
will be nonzero (when it eventually exits). Use of -delete
automatically turns on the -depth option.
find何らかの理由で使用できない場合は、ここでzsh(または他のシェル)でそれを行う方法があります。zshされzsh、これを行う簡単な方法は、おそらくありますが、私は以来、bash男は、これは私が思い付いたものです:
for file in *; do if [[ ! "$file" == *.dmg ]]; then rm $file; fi; done
find [Process completed]
find。findただし、発生しないはずの問題について質問を投稿することをお勧めします。その場合、の出力を含めますtype -a find。
rm !(*.dmg)、後shopt -s extglob。
find is a shell function find is /usr/bin/find
/usr/bin/find。findbash構成ファイルの1つで定義された関数が定義されています。OSXを使用しているので、おそらくになり~/.profileます。
rm -r secrets/!(directory)、それが求め続けnumber expectedたり、時にはそれが私に与えますevent not found: directory