4

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.

don_crissti
  • 82,805
Jeeva
  • 245

2 Answers2

2

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

find . -name output -type d -exec find {} -mindepth 1 -delete \;
ilkkachu
  • 138,973
1

You could use the following ways depending on the version of find you may have.

GNU find:

find . -type f -path '*/output/*' -exec echo rm -f {} \;

POSIX-find

find . -type d -name output -exec sh -c 'find "$1"/. ! -name . -prune -type f -exec rm -f \{\} \;' {} {} \;