Linux – Delete all sub-directories except one

bashlinux

Suppose under the current directory, there are multiple sub-directories, and one is called A.

How to delete all sub-directories except A with Bash?

Best Answer

Bash has extended globbing (first test, then remove the echo):

shopt -s extglob
echo rm -rf !(A)
Related Topic