Have linux remove all but on directory with bash

Posted by Dark Training on July 16, 2010 tags: | linux

Have you ever wanted to clear a entire directory EXECPT one file or folder?

Here is how you can do it with just one line, cd in to the directory you want to effect then,:

ls *|grep -v f1|xargs rm -rf

That's it! If you need to run the command with sudo you would just run it as:

sudo ls *|grep -v f1|xargs sudo rm -rf