Glob
- shopt -s extglob
- rm -v !("filename")
- rm -v !("filename1"|"filename2")
- rm -v !(*.zip|*.odt)
- shopt -u extglob
Find
- find /directory/ -type f -not -name 'PATTERN' -delete
- find /directory/ -type f -not -name 'PATTERN' -print0 | xargs -0 -I {} rm {}
- find /directory/ -type f -not -name 'PATTERN' -print0 | xargs -0 -I {} rm [options] {}
- find . -type f -not \(-name '*gz' -or -name '*odt' -or -name '*.jpg' \) -delete
Glob ignore
- cd test
- GLOBIGNORE=*.odt:*.iso:*.txt
- rm -v *
- unset GLOBIGNORE
(source)