文件地址为 /sample/resample/
假设resample/
下有多个文件夹含有名为’testlog.txt’ 的文件,需要找到该指定文件并全部删除
$ cd /sample/
$ find rmsample -maxdepth 3 -name "textlog.txt" |xargs rm -rf
-maxdepth 3
查找三层目录/sample/resample/A/B/
中符合条件 -name "textlog.txt"
的文件并删除掉!
|xargs
参数传递过滤器
找到根目录下所有的以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”)
这样只会查找三层目录中符合条件的文件并删除掉!