命令行递归删除匹配的文件和目录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令行递归删除匹配的文件和目录相关的知识,希望对你有一定的参考价值。

  1. # This searches recursively for all directories (-type d) in the hierarchy starting at "." (current directory), and finds those whose name is '.svn'; the list of the found directories is then fed to rm -rf for removal.
  2.  
  3. find . -name '.svn' -type d | xargs rm -rf
  4.  
  5. # If you want to try it out, try
  6.  
  7. find . -name '.svn' -type d | xargs echo
  8.  
  9. # This should provide you with a list of all the directories which would be recursively deleted.
  10.  
  11. ==================================
  12.  
  13. # Another way is:
  14.  
  15. find . -name ".svn" -exec rm -rf {} ;
  16.  
  17. #Try something like this first to do a dry run:
  18.  
  19. find . -name ".svn" -exec echo {} ;
  20.  
  21. #Note that the empty braces get filled in with the file names and the escaped semicolon ends the command that is executed (starting after the "-exec").

以上是关于命令行递归删除匹配的文件和目录的主要内容,如果未能解决你的问题,请参考以下文章

文件目录管理类命令

sh 从命令行递归删除文件

在Windows中递归删除具有指定名称的文件夹的命令行工具?

sed命令:删除匹配行和替换

Linux常用命令

rm命令