删除 Linux/Mac 临时文件

284 阅读1分钟

找到根目录下所有的以 test 开头的文件并把查找结果当做参数传给 rm -rf 命令进行删除:

1、find / -name “test” |xargs rm -rf
2、find / -name “test” -exec rm -rf {} ;
3、rm -rf $(find / -name “test”)

如果想指定递归深度,可以这样:

1、find / -maxdepth 3 -name “.mp3” |xargs rm -rf
2、find / -maxdepth 3 -name “test” -exec rm -rf {} ;
3、rm -rf $(find / -maxdepth 3 -name “test”)

这样只会查找三层目录中符合条件的文件并删除掉!