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.

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

Comments

0

Use xargs with pipe lining -

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.