Remove all files except some from a directory

find [path] -type f -not -name ‘textfile.txt’ -not -name ‘backup.tar.gz’ -delete If you don’t specify -type f find will also list directories, which you may not want. Or a more general solution using the very useful combination find | xargs: find [path] -type f -not -name ‘EXPR’ -print0 | xargs -0 rm — for example, … Read more