# if you are using a loop
shopt -s extglob
rm -rf !("abc.txt" | "abc.log" ) # others will be removed except these two
OR
rm -v !(*.zip|*.odt)
shopt -u extglob
# Basic syntax:
find /directory/to/search -type f -name "pattern_to_match" ! -name "pattern_to_ignore" -delete
# Example usage:
touch file1 file2 file3
# This will delete all files except those containing "3"
find . -type f -name "*file*" ! -name "*3*" -delete
# Note, if I'm only deleting a moderate number of files, I prefer to use the
# following which asks for confirmation before deleting:
find . -type f -name "*file*" ! -name "*3*" -ok rm -- {} ;