답변:
이 extended_glob옵션은 zsh 자체 확장 glob 구문을 제공합니다 .
setopt extended_glob
rm -- ^*.dmg
rm -- ^*.(dmg|txt)
ksh globsksh_glob 를 얻 도록 옵션을 설정할 수 있습니다 . 음수 패턴이 단어의 마지막 항목 인 일반적인 경우 zsh는 괄호를 glob 한정자로 구문 분석 할 수 있습니다 (ksh 에뮬레이션 모드에서는이 작업을 수행하지 않음).
setopt ksh_glob
rm -- !(*.dmg|*.txt)
setopt no_bare_glob_qual
rm -- !(*.dmg)
ksh_glob옵션을 설정하지 않았 음을 나타냅니다 . “event not found : directory”는 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), after shopt -s extglob.
find is a shell function find is /usr/bin/find
/usr/bin/find. findbash 구성 파일 중 하나에 정의 된 함수가 있습니다. OSX를 사용하고 있기 때문에 아마도 그렇습니다 ~/.profile.
파일을 제거하는 또 다른 방법은 함께 find, xargs그리고 rm:
find . -mindepth 1 -maxdepth 1 ! -name '*.dmg' -print0 | xargs -0 rm
rm -r secrets/!(directory)그것을 요구number expected하거나 때때로 그것은 나에게 준다event not found: directory