How to delete the content of all subdirectories named “output”

filesfind

I downloaded a project from web.When building the project it produces output files in folder named output.The problem is there are many folders with same name.I need to manually delete the files in all output directories.

I used this command

find . -type d -name "output" -print

It displays the location of all directories with same name.

Then i used this command

find . -type d -name "output" -delete

find: cannot delete ‘./output’: Directory not empty

I don't want to delete the output folder I want to delete all the files under the output folder name.

Best Answer

If your find has -mindepth and -delete (at least GNU or BSD):

find . -name output -type d -exec find {} -mindepth 1 -delete \;
Related Question