方法1

find ~/examples/ -name '*data*' -exec rm -rf {}

这个命令的执行效果如下所示

root@hgdm:~# find ~/examples/ -name '*data*' /root/examples/data333.txt /root/examples/data555.txt /root/examples/data1.txt /root/examples/data2.txt /root/examples/data22.txt /root/examples/user_data.txt /root/examples/data111.txt /root/examples/data55.txt /root/examples/data444.txt /root/examples/data3.txt /root/examples/data11.txt /root/examples/data4.txt /root/examples/data5.txt /root/examples/data44.txt /root/examples/data33.txt /root/examples/data222.txt root@hgdm:~# find ~/examples/ -name '*data*' -exec rm -rf {} root@hgdm:~# find ~/examples/ -name '*data*' root@hgdm:~#

linux怎么删除重复的文件夹(如何删除名称含指定词的全部文件)(1)

方法1

方法2

find ~/examples/ -name '*data*' -print0 | xargs -0 rm -rf

这个命令的执行效果如下所示

root@hgdm:~# find ~/examples/ -name '*data*' -print0 | xargs -0 /root/examples/data333.txt /root/examples/data555.txt /root/examples/data1.txt /root/examples/data2.txt /root/examples/data22.txt /root/examples/user_data.txt /root/examples/data111.txt /root/examples/data55.txt /root/examples/data444.txt /root/examples/data3.txt /root/examples/data11.txt /root/examples/data4.txt /root/examples/data5.txt /root/examples/data44.txt /root/examples/data33.txt /root/examples/data222.txt root@hgdm:~# find ~/examples/ -name '*data*' -print0 | xargs -0 rm -rf root@hgdm:~# find ~/examples/ -name '*data*' -print0 | xargs -0 root@hgdm:~#

方法3 此方法不可靠,不可轻易使用

find ~/examples/ | grep 'data' | xargs rm -rf

这个命令的执行效果如下所示

root@hgdm:~# find ~/examples/ | grep 'data' /root/examples/data333.txt /root/examples/data555.txt /root/examples/data1.txt /root/examples/data2.txt /root/examples/data22.txt /root/examples/user_data.txt /root/examples/data111.txt /root/examples/data55.txt /root/examples/data444.txt /root/examples/data3.txt /root/examples/data11.txt /root/examples/data4.txt /root/examples/data5.txt /root/examples/data44.txt /root/examples/data33.txt /root/examples/data222.txt root@hgdm:~# find ~/examples/ | grep 'data' | xargs rm -rf root@hgdm:~# find ~/examples/ | grep 'data' root@hgdm:~#

,