Now if you have a problem where you wanna delete a couple of folders in a directory it’s easy to do that in a one liner
$ rm -rf folder_1 folder_2
but what if you want to delete all but those specific directories? Today my college showed me this amazing trick for finding everything but that
$ find . -maxdepth 1 ! -name folder_1 ! -name folder_2
which lists all the other folders in that particular directory and then that can easily be piped to rm.
$ find . -maxdepth 1 ! -name folder_1 ! -name folder_2 | xargs rm -rf
Sorry, comments are closed for this article.