rm -rf except 1

rm -rf except

ls | grep -v 'file-to-keep' | xargs rm

Here is what the above code is Doing:
1. Find all files in the current directory that end with .txt
2. Pipe the results to grep, which filters out the file we want to keep
3. Pipe the results to xargs, which runs the rm command on all the files

Similar Posts