Skip to content

Remove all files except a few

Victor Barrera edited this page Jan 13, 2017 · 1 revision

How to remove all files except the ones you want:

First, expand rm capabilities by: shopt -s extglob

Then use find and remove: find . ! -name 'file.txt' -type f -exec rm -f {} +