Anda bisa menggunakan findbukan shell Anda:
find . -mindepth 1 -maxdepth 1 ! -name "*.dmg" -delete
Dari 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.
Jika Anda tidak dapat menggunakan finduntuk alasan apa pun, berikut adalah cara untuk melakukannya dengan zsh(atau cangkang lain). zshmenjadi zsh, mungkin ada cara sederhana untuk melakukan hal ini tapi karena aku bashpria, ini adalah apa yang saya datang dengan:
for file in *; do if [[ ! "$file" == *.dmg ]]; then rm $file; fi; done
rm -r secrets/!(directory)terus memintanumber expectedatau kadang-kadang itu memberi sayaevent not found: directory