Вы можете использовать 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
rm -r secrets/!(directory)он продолжает спрашивать,number expectedа иногда и даетevent not found: directory