Remove all files except one with find and rm
$ find . ! -name 'file.txt' -type f -exec rm -f {} +
For more information about the options run man find
.
See also https://yctct.com/tagged/find and https://yctct.com/tagged/exec
personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki find