using rm *text*
you can delete all files which have a certain string in them. How would I make it so that it removes every file except for the ones with the specific wildcard?
I have attempted to use other things I've found, such as:
find . -type f -print0 | xargs --null grep -Z -L 'text' | xargs --null rm
or
grep -r -L -Z 'text' . | xargs --null rm
but these do not work. Instead, they are deleting all files in a given directory.
How could I do this?
extglob
) provides a negation operator - see for example How to delete all files except one named file from a specific folderfind
attempts is that they grep for the names of files whose contents do not matchtext