HassanF
HassanF

Reputation: 455

find and remove multiple file using linux command

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.

Upvotes: 0

Views: 3504

Answers (2)

Razib
Razib

Reputation: 11173

Use xargs with pipe lining -

$ find . -name *.class | xargs rm *

Upvotes: 0

Thomas Dickey
Thomas Dickey

Reputation: 54583

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:

Upvotes: 1

Related Questions