How to delete all directories except one on Linux

less than 1 minute read

If you have a list of directories out of which you have to delete all except one, you can use the following command:

rm -rf !("do_not_delete_this_directory")

Updated: