आप 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