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:~#
方法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:~#
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:~#