Você pode usar em findvez do seu 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.
Se você não puder usá-lo findpor qualquer motivo, aqui está uma maneira de fazer isso com zsh(ou outras conchas). zshsendo zsh, provavelmente existe uma maneira mais simples de fazer isso, mas como eu sou um bashcara, é isso que eu criei:
for file in *; do if [[ ! "$file" == *.dmg ]]; then rm $file; fi; done
rm -r secrets/!(directory)ele continua pedindonumber expectedou às vezes isso me dáevent not found: directory