Puede usar en findlugar de su shell:
find . -mindepth 1 -maxdepth 1 ! -name "*.dmg" -delete
De 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.
Si no puede usarlo findpor alguna razón, aquí hay una manera de hacerlo zsh(u otros shells). zshsiendo zsh, es probable que haya una manera más sencilla de hacer esto, pero ya que soy un bashchico, esto es lo que ocurrió:
for file in *; do if [[ ! "$file" == *.dmg ]]; then rm $file; fi; done
rm -r secrets/!(directory), sigue preguntandonumber expectedo, a veces, me daevent not found: directory