A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Delete all files except one on linux

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