0

I have a directory named classes which contains a lot of sub-directories -

classes  
  |-security  
  |-registration  
  |-service  
 ....  

Each of these directory contains a lot of java files and their compiled classes files. I want to remove all the class file.

Going to classes directory I can list out all the class file using find command -

$ find . -name *.class  

Is there any command in linux to remove all the classes file under the classes directory.

HassanF
  • 465
  • 1
  • 6
  • 13

2 Answers2

1

The usual answer uses the -exec option of find:

find . -name "*.class" -exec rm {} \;

Be sure to quote the wildcard, to ensure that it is passed into find (rather than globbed by the shell, first).

For further discussion, see these questions:

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
0

Use xargs with pipe lining -

$ find . -name *.class | xargs rm *
Razib
  • 10,965
  • 11
  • 53
  • 80
  • 1
    Mind to explain this a bit? Although, you are not using xargs, but a pipe to rm, which isn't necessary and may slow things down when compared to `-exec rm`. – Markus W Mahlberg Mar 15 '15 at 11:01