Say you wanted to delete all files in the current directory except README.txt
. You could accomplish this by using find:
$ find . -type f ! -name 'README.txt' -delete
Similarly to delete everything but a certain extension:
$ find . -type f ! -name '*.tmp' -delete
Peace!!