简体   繁体   English

使用linux命令查找并删除多个文件

[英]find and remove multiple file using linux command

I have a directory named classes which contains a lot of sub-directories - 我有一个名为classes的目录,其中包含很多子目录-

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

Each of these directory contains a lot of java files and their compiled classes files. 这些目录中的每个目录都包含许多java文件及其编译的类文件。 I want to remove all the class file. 我想删除所有的类文件。

Going to classes directory I can list out all the class file using find command - 转到classes目录,我可以使用find命令列出所有类文件-

$ find . -name *.class  

Is there any command in linux to remove all the classes file under the classes directory. linux中是否有任何命令可以删除classes目录下的所有classes文件。

The usual answer uses the -exec option of find : 通常的答案使用find-exec选项:

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). 确保引用通配符,以确保将通配符传递给find (而不是首先由shell锁定)。

For further discussion, see these questions: 有关进一步的讨论,请参见以下问题:

xargs与管道衬里配合使用-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM