linux cli remove all except 2 folders
- User
linux cli remove all except 2 folders
Assistant
To remove all files and folders in a directory except for two specific folders, you can use the
rmcommand with some clever use of shell globbing orfind.Here's how to do it safely using the bash shell:
✅ Method 1: Using
rmwith extended globbing (simple & clean)# Enable extended globbing shopt -s extglob # Remove everything except folder1 and folder2 rm -rf !(folder1|folder2)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.