Wake Me Up When September Ends.

A wanderer capable of grasping the beauty of the grass, with a heart full of ancient charm, and a fondness for playful wit. Those who understand my words are knowledgeable individuals; those who decipher my code truly comprehend the essence. I am a wandering code swordsman, carrying my skills and riding freely through the digital world.

🤳 批量删除大量文件

有时候一些日志目录或调试目录下会生成大量文件,久而久之目录下会有很多文件,直接用rm 命令删除会提示too many 参数过多的错误!

可以借助find配合rm来实现对大批量相同文件删除操作!

比如对tmp目下大量以xhprof为后缀名文件进行删除:

find ./ -type f -name "*.xhprof" -exec rm {} \;
  1. find: 这是用于在文件系统中搜索文件和目录的命令。
  2. ./: 这表示从当前目录(也就是所在的tmp目录)开始搜索。
  3. -type f: 这是 find 命令的选项之一,表示只搜索普通文件(不包括目录等)。
  4. -name “*.xhprof” 表示只匹配以xhprof为后缀名文件
  5. -exec rm {} ;: 这部分告诉 find 命令对每个找到的文件执行 rm 命令。{} 是一个占位符,会被找到的文件名替换;; 表示命令的结尾。