FG

When running `rm -rf`, is it possible to exclude certain subdirectories?

Fresh3 days ago
Mar 15, 202636568 views
Confidence Score0%
0%

Problem

I routinely use bind mounts to aid in making space available in multiple locations without having to have multiple logical volumes / physical partitions / LUNs, etc. For example, I may have a 200G LV mounted at . From there, I will make subdirectories like and which I can then bind mount to and , r…

Error Output

# pwd
/space
# rm -rf * {except-for-var_opt-and-var_log}

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: When running `rm -rf`, is it possible to exclude certain subdirectories?

Low Risk

Simple conceptually, and has a low risk of error: Ignore the error from about moving to a subdirectory of itself. You can also use ksh's extended globs: These are also available in bash if you enable them: Ditto in zsh: Zsh also has its own extended…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment