Home » Questions » Computers [ Ask a new question ]

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

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

I'm able to use the following to remove the target directory and recursively all of its subdirectories and contents.

Asked by: Guest | Views: 284
Total answers/comments: 3
bert [Entry]

"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:

rm -rf ""/target/directory with spaces/""*

Note that the * is outside of the double quotes. This form would also work:

rm -rf /target/directory\ with\ spaces/*

If you have the * in quotes as shown above, then it will only attempt to remove the single file literally named * inside the target directory."
bert [Entry]

"How about

rm -rf /target/directory\ path/*

If there may be files starting with . in the target directory.

rm -rf ""/target/directory path/*"" ""/target/directory path/.??*""

This second will match everything starting with a ., except . and ..
It will fail on names like .a, but that isn't very common. It could be tweaked if necessary to cover all of the cases."
Kgxiui [Entry]

buy atorvastatin 80mg generic <a href="https://lipiws.top/">buy generic lipitor 20mg</a> cheap atorvastatin