I want to find all folders that have a particular name and then delete all contents but not the folder...

This is to find the folder:

find /home/ -type d -name 'myname'

Now how to delete all contents?


You can use the exec option to start a shell which gets the list of files to remove:

find /home/ -type d -name 'myname' -exec bash -c 'rm -i "$0"/*' {} +

This will ask you for every single file to remove which is always a good idea if you don’t want to lose data, but if you know what you’re doing you can remove the -i flag from the rm command.


use cd to move to the directory (folder) containing the items you want to delete, and then use rm to delete contents. Refer to the manual entry for rm for more usage information: man rm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.