FG
💻 Software

How do I recursively remove subdirectories and files, but not the first parent directory?

Fresh5 days ago
Mar 15, 202682968 views
Confidence Score0%
0%

Problem

I'm able to use the following to remove the target directory and recursively all of its subdirectories and contents. However, I do not want the target directory to be removed. How can I remove just the files in the target, the subdirectories, and their contents?

Error Output

find '/target/directory/' -type d -name '*' -print0 | xargs -0 rm -rf

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How do I recursively remove subdirectories and files, but not the first parent directory?

Low Risk

The previous answer is almost correct. However, you shouldn't quote the shell glob characters if you want them to work. So, this is the command you're looking for: Note that the * is outside of the double quotes. This form would also work: If you ha…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment